fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. cin.sync_with_stdio(0);
  28. // freopen("mahdi.in","r",stdin);
  29. int T;
  30. cin >> T;
  31.  
  32. for(int t =0; t < T; t++) {
  33. string S;
  34. int L,N;
  35. int R[2];
  36. cin >> S >> L >> R[0] >> R[1] >> N;
  37.  
  38. vector< vector< pair<int,int> > > A(26);
  39. vector<int> last(N);
  40. vector<int> Ls(N);
  41. vector<int> Rs[2];
  42. Rs[0].resize(N); Rs[1].resize(N);
  43. // string,state
  44. for(int i =0; i < N; i++) {
  45. string s;
  46. cin >> s >> Ls[i] >> Rs[0][i] >> Rs[1][i];
  47. last[i] =s[0]-'a';
  48. A[s[0]-'a'].push_back(make_pair(0,i));}
  49.  
  50. vector<bool> ans(N,false);
  51. for(int i =0; i < L; i++) {
  52. vector< pair<int,int> > upd =A[S[i]-'a'];
  53. A[S[i]-'a'].clear();
  54. for(int i =0; i < upd.size(); i++) {
  55. upd[i].ff++;
  56. int id =upd[i].ss;
  57. if(Ls[id] == upd[i].ff) {
  58. ans[id] =true;
  59. continue;}
  60. int x =(last[id]*Rs[0][id]+upd[i].ff*Rs[1][id])%26;
  61. if(x < 0) x +=26;
  62. last[id] =x;
  63. A[x].push_back(upd[i]);}
  64.  
  65. if(i == L-1) break;
  66. int x =((S[i]-'a')*R[0]+(i+1)*R[1])%26;
  67. if(x < 0) x +=26;
  68. S +=(char)('a'+x);}
  69.  
  70. cout << "Case " << t+1 << ":\n";
  71. for(int i =0; i < N; i++) {
  72. if(ans[i]) cout << "BRAVO\n";
  73. else cout << "REPEAT\n";}
  74. }
  75. return 0;}
  76.  
  77. // look at my code
  78. // my code is amazing
Success #stdin #stdout 0s 3480KB
stdin
1
a 100 13 37
3
a 11 11 311
b 9 13 22
d 5 31 12
stdout
Case 1:
REPEAT
REPEAT
BRAVO