fork(1) download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. vector<vector<int>> x(50, vector<int>(50, 0));
  5. int Div[51],K;
  6. inline int solve() {
  7. int q = 1, p = 0;
  8. for (int i = 0; i < 50; i++) {
  9. for (int j = 0; j < 50; j++) {
  10. if (x[i][j] == 1)p += q;
  11. q *= 2; q %= K; p %= K;
  12. }
  13. }
  14. return p;
  15. }
  16. inline int Query(int i1, int i2, int i3, int i4) {
  17. cout << "? " << i1 << ' ' << i2 << ' ' << i3 << ' ' << i4 << endl;
  18. int Va; cin >> Va;
  19. return Va;
  20. }
  21. inline void solve2(int row, int col, int p1) {
  22. int i = row, j = col;
  23. if (p1 == 0) { x[i][j] = 0; x[i][j + 1] = 0; x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  24. else if (p1 == 4) { x[i][j] = 1; x[i][j + 1] = 1; x[i + 1][j] = 1; x[i + 1][j + 1] = 1; }
  25. else {
  26. int p2 = Query(i, j, i, j + 1), p3 = p1 - p2;
  27. if (p2 == 0) { x[i][j] = 0; x[i][j + 1] = 0; }
  28. if (p2 == 2) { x[i][j] = 1; x[i][j + 1] = 1; }
  29. if (p3 == 0) { x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  30. if (p3 == 2) { x[i + 1][j] = 1; x[i + 1][j + 1] = 1; }
  31. if (p2 == 1 && p3 == 1) {
  32. int p4 = Query(i, j, i + 1, j);
  33. if (p4 == 0) { x[i][j] = 0; x[i + 1][j] = 0; x[i][j + 1] = 1; x[i + 1][j + 1] = 1; }
  34. else if (p4 == 2) { x[i][j] = 1; x[i + 1][j] = 1; x[i][j + 1] = 0; x[i + 1][j + 1] = 0; }
  35. else {
  36. int p5 = Query(i, j, i, j); x[i][j] = p5;
  37. x[i + 1][j] = p4 - p5; x[i][j + 1] = p2 - p5; x[i + 1][j + 1] = p3 - x[i + 1][j];
  38. }
  39. }
  40. else {
  41. if (p2 == 1) { x[i][j] = Query(i, j, i, j); x[i][j + 1] = 1 - x[i][j]; }
  42. if (p3 == 1) { x[i + 1][j] = Query(i + 1, j, i + 1, j); x[i + 1][j + 1] = 1 - x[i + 1][j]; }
  43. }
  44. }
  45. }
  46. inline void solve4(int row, int col, int p1) {
  47. int i = row, j = col;
  48. if (p1 == 0)return;
  49. int p2 = Query(i, j, i + 1, j + 3), p3 = p1 - p2;
  50. if (p2 == 0) {}
  51. if (p2 == 8) { for (int I = i + 0; I < i + 2; I++) { for (int J = j + 0; J < j + 4; J++) { x[I][J] = 1; } } }
  52. if (p3 == 0) {}
  53. if (p3 == 8) { for (int I = i + 2; I < i + 4; I++) { for (int J = j + 0; J < j + 4; J++) { x[I][J] = 1; } } }
  54. if (p2 >= 1 && p2 <= 7 && p3 >= 1 && p3 <= 7) {
  55. int p4 = Query(i, j, i + 3, j + 1), p5 = p1 - p4;
  56. if (p4 != 0 && p5 != 0) {
  57. int p10 = Query(i, j, i + 1, j + 1), p11 = p2 - p10;
  58. int p12 = p4 - p10, p13 = p5 - p11;
  59. solve2(i, j, p10); solve2(i, j + 2, p11);
  60. solve2(i + 2, j, p12); solve2(i + 2, j + 2, p13);
  61. }
  62. if (p4 == 0) {
  63. solve2(i, j, 0); solve2(i + 2, j, 0);
  64. solve2(i, j + 2, p2); solve2(i + 2, j + 2, p3);
  65. }
  66. else if (p5 == 0) {
  67. solve2(i, j, p2); solve2(i + 2, j, p3);
  68. solve2(i, j + 2, 0); solve2(i + 2, j + 2, 0);
  69. }
  70. }
  71. else {
  72. if (p2 >= 1 && p2 <= 7) { int p6 = Query(i, j, i + 1, j + 1), p7 = p2 - p6; solve2(i, j, p6); solve2(i, j + 2, p7); }
  73. if (p3 >= 1 && p3 <= 7) { int p8 = Query(i + 2, j, i + 3, j + 1), p9 = p3 - p8; solve2(i + 2, j, p8); solve2(i + 2, j + 2, p9); }
  74. }
  75. }
  76. inline void saiki(int row, int col, int hs, int ws, int p1) {
  77. if (row >= 50 || col >= 50)return;
  78. if (hs == 2 && ws == 2) { solve2(row, col, p1); return; }
  79. if (hs == 4 && ws == 4) { solve4(row, col, p1); return; }
  80. if (hs > ws) {
  81. int E1 = p1;
  82. int EE1, EE2;
  83. if (E1 == hs*ws) { EE1 = ws*Div[hs]; EE2 = ws*(hs - Div[hs]); }
  84. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  85. else { EE1 = Query(row, col, row + Div[hs] - 1, col + ws - 1); EE2 = E1 - EE1; }
  86. saiki(row, col, Div[hs], ws, EE1);
  87. saiki(row + Div[hs], col, hs - Div[hs], ws, EE2);
  88. }
  89. else {
  90. int E1 = p1;
  91. int EE1, EE2;
  92. if (E1 == hs*ws) { EE1 = hs*Div[ws]; EE2 = hs*(ws - Div[ws]); }
  93. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  94. else { EE1 = Query(row, col, row + hs - 1, col + Div[ws] - 1); EE2 = E1 - EE1; }
  95. saiki(row, col, hs, Div[ws], EE1);
  96. saiki(row, col + Div[ws], hs, ws - Div[ws], EE2);
  97. }
  98. }
  99. int main() {
  100. int H, W, N; cin >> H >> W >> N>>K;
  101. for (int i = 1; i <= 50; i++) {
  102. if (i > 32)Div[i] = 32;
  103. else if (i > 16)Div[i] = 16;
  104. else if (i > 8)Div[i] = 8;
  105. else if (i > 4)Div[i] = 4;
  106. else if (i > 2)Div[i] = 2;
  107. else if (i > 1)Div[i] = 1;
  108. }
  109. saiki(0, 0, 50, 50, 250);
  110. cout << "! " << solve() << endl;
  111. return 0;
  112. }
Runtime error #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
? 0 0 49 31
? 0 0 31 31
? 0 0 31 15
? 0 0 15 15
? 0 0 15 7
? 0 0 7 7
? 0 0 7 3
? 0 0 3 3
? 0 0 1 3
? 32 0 49 15
? 32 0 47 15
? 32 0 47 7
? 32 0 39 7
? 32 0 39 3
? 32 0 35 3
? 32 0 33 3
? 32 16 47 31
? 32 16 47 23
? 32 16 39 23
? 32 16 39 19
? 32 16 35 19
? 32 16 33 19
? 48 16 49 23
? 48 16 49 19
? 48 16 49 17
? 48 16 48 17
? 48 24 49 27
? 48 24 49 25
? 48 24 48 25
? 48 28 49 29
? 48 28 48 29
? 48 30 48 31
? 0 32 31 49
? 0 32 15 49
? 0 32 15 47
? 0 32 15 39
? 0 32 7 39
? 0 32 7 35
? 0 32 3 35
? 0 32 1 35
? 16 32 31 47
? 16 32 31 39
? 16 32 23 39
? 16 32 23 35
? 16 32 19 35
? 16 32 17 35
? 16 48 23 49
? 16 48 19 49
? 16 48 17 49
? 16 48 16 49
? 24 48 27 49
? 24 48 25 49
? 24 48 24 49
? 28 48 29 49
? 28 48 28 49
? 30 48 30 49
? 32 32 49 47
? 32 32 47 47
? 32 32 47 39
? 32 32 39 39
? 32 32 39 35
? 32 32 35 35
? 32 32 33 35
? 48 32 49 39
? 48 32 49 35
? 48 32 49 33
? 48 32 48 33
? 48 40 49 43
? 48 40 49 41
? 48 40 48 41
? 48 44 49 45
? 48 44 48 45
? 48 46 48 47
? 32 48 47 49
? 32 48 39 49
? 32 48 35 49
? 32 48 33 49
? 32 48 32 49
? 40 48 43 49
? 40 48 41 49
? 40 48 40 49
? 44 48 45 49
? 44 48 44 49
? 46 48 46 49
? 48 48 48 49