fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. #define MAXN 14
  8.  
  9. int N, M, K;
  10. string S;
  11.  
  12. int A[8 * MAXN];
  13.  
  14. int calc(int y, int x, int a, int b) {
  15. return (1ll * x * (A[y * 8 + a * 4 + b * 2] + 1) +
  16. A[y * 8 + a * 4 + b * 2 + 1]) % M;
  17. }
  18.  
  19. bool solve_and(int y, int x, bool a);
  20.  
  21. bool solve_or(int y, int x) {
  22. if(y == N) return x <= K || x + K >= M;
  23. bool mv = rand() & 1;
  24. return solve_and(y, x, mv) || solve_and(y, x, !mv);
  25. }
  26.  
  27. bool solve_and(int y, int x, bool a) {
  28. bool mv = rand() & 1;
  29. return solve_or(y + 1, calc(y, x, a, mv)) &&
  30. solve_or(y + 1, calc(y, x, a, !mv));
  31. }
  32.  
  33. int main() {
  34. freopen("cowrun.in", "r", stdin);
  35. freopen("cowrun.out", "w", stdout);
  36.  
  37. cin >> N >> M >> K;
  38. cin >> S;
  39. for(int i = 0; i < 8 * N; i++) {
  40. cin >> A[i];
  41. }
  42.  
  43. int x = 0;
  44. for(int i = 0; i < N; i++) {
  45. if(solve_and(i, x, true)) {
  46. cout << 'B';
  47. x = calc(i, x, true, S[i] == 'B');
  48. } else {
  49. cout << 'T';
  50. x = calc(i, x, false, S[i] == 'B');
  51. }
  52. }
  53. cout << endl;
  54. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty