fork download
  1. #include<iostream>
  2. #include<vector>
  3. #include<ctime>
  4. //#include"BombsGame.h"
  5. using namespace std;
  6. vector<vector<int>> x(50, vector<int>(50, 0));
  7. int Div[51];
  8. int scnt=0,KK=0;
  9. inline int solve() {
  10. int q = 1, p = 0;
  11. for (int i = 0; i < 50; i++) {
  12. for (int j = 0; j < 50; j++) {
  13. if (x[i][j] == 1)p += q;
  14. q *= 2; q %= KK; p %= KK;
  15. }
  16. }
  17. return p;
  18. }
  19. inline int Query(int i1, int i2, int i3, int i4) {
  20. cout << "? " << i1 << ' ' << i2 << ' ' << i3 << ' ' << i4 << endl;
  21. int Va; cin >> Va;
  22. return Va;
  23. }
  24. inline void solve3(int row, int col, int p1) {
  25. int i = row, j = col;
  26. if(p1!=1)return;
  27. if (p1 == 0) { x[i][j] = 0; x[i][j + 1] = 0; x[i + 1][j] = 0; x[i + 1][j + 1] = 0; return; }
  28. else if (p1 == 4) { x[i][j] = 1; x[i][j + 1] = 1; x[i + 1][j] = 1; x[i + 1][j + 1] = 1; return; }
  29.  
  30. if (x[i][j] != -1) {
  31. if (x[i][j] == 1) { scnt++; x[i][j + 1] = 0; x[i + 1][j] = 0; x[i + 1][j + 1] = 0; return; }
  32. int p2 = Query(i, j, i, j + 1), p3 = p1 - p2;
  33. if (p2 == 0) { x[i][j] = 0; x[i][j + 1] = 0; }
  34. if (p3 == 0) { x[i + 1][j] = 0; x[i + 1][j + 1] = 0; x[i][j + 1] = 1; return; }
  35. if (p3 == 1) {
  36. if (j == 48) { x[i + 1][j] = Query(i + 1, j, i + 1, j); x[i + 1][j + 1] = 1 - x[i + 1][j]; }
  37. else {
  38. int v1 = Query(i + 1, j + 1, i + 1, j + 2);
  39. if (v1 == 0) { x[i + 1][j] = 1; x[i + 1][j + 1] = 0; x[i + 1][j + 2] = 0; }
  40. if (v1 == 2) { x[i + 1][j] = 0; x[i + 1][j + 1] = 1; x[i + 1][j + 2] = 1; }
  41. if (v1 == 1) { x[i + 1][j + 1] = -2; }
  42. }
  43. }
  44. }
  45.  
  46. if (x[i + 1][j] != -1) {
  47. if (x[i + 1][j] == 1) { scnt++; x[i][j + 1] = 0; x[i][j] = 0; x[i + 1][j + 1] = 0; return; }
  48. int p2 = Query(i, j, i, j + 1), p3 = p1 - p2;
  49. if (p2 == 0) { x[i][j] = 0; x[i][j + 1] = 0; x[i + 1][j + 1] = 1; return; }
  50. if (p3 == 0) { x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  51. if (p2 == 1) {
  52. if (j == 48) { x[i][j] = Query(i, j, i, j); x[i][j + 1] = 1 - x[i][j]; }
  53. else {
  54. int v1 = Query(i, j + 1, i, j + 2);
  55. if (v1 == 0) { x[i][j] = 1; x[i][j + 1] = 0; x[i][j + 2] = 0; }
  56. if (v1 == 2) { x[i][j] = 0; x[i][j + 1] = 1; x[i][j + 2] = 1; }
  57. if (v1 == 1) { x[i][j + 1] = -2; }
  58. }
  59. }
  60. }
  61. }
  62. inline void solve2(int row, int col, int p1) {
  63. int i = row, j = col;
  64.  
  65. if ((x[i][j] != -1 || x[i + 1][j] != -1) && p1 == 1) { solve3(i, j, p1); }
  66. else {
  67. if (p1 == 0) { x[i][j] = 0; x[i][j + 1] = 0; x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  68. else if (p1 == 4) { x[i][j] = 1; x[i][j + 1] = 1; x[i + 1][j] = 1; x[i + 1][j + 1] = 1; }
  69. else {
  70. int p2 = Query(i, j, i, j + 1), p3 = p1 - p2;
  71. if (p2 == 0) { x[i][j] = 0; x[i][j + 1] = 0; }
  72. if (p2 == 2) { x[i][j] = 1; x[i][j + 1] = 1; }
  73. if (p3 == 0) { x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  74. if (p3 == 2) { x[i + 1][j] = 1; x[i + 1][j + 1] = 1; }
  75. if (p2 == 1 && p3 == 1) {
  76. int p4 = Query(i, j, i + 1, j);
  77. if (p4 == 0) { x[i][j] = 0; x[i + 1][j] = 0; x[i][j + 1] = 1; x[i + 1][j + 1] = 1; }
  78. else if (p4 == 2) { x[i][j] = 1; x[i + 1][j] = 1; x[i][j + 1] = 0; x[i + 1][j + 1] = 0; }
  79. else {
  80. int p5 = Query(i, j + 1, i, j + 1);
  81. x[i][j + 1] = p5;
  82. x[i][j] = p2 - p5;
  83. x[i + 1][j] = p4 - x[i][j];
  84. x[i + 1][j + 1] = p3 - x[i + 1][j];
  85. }
  86. }
  87. else {
  88. if (p2 == 1) {
  89. if (j == 48) { x[i][j] = Query(i, j, i, j); x[i][j + 1] = 1 - x[i][j]; }
  90. else {
  91. int v1 = Query(i, j + 1, i, j + 2);
  92. if (v1 == 0) { x[i][j] = 1; x[i][j + 1] = 0; x[i][j + 2] = 0; }
  93. if (v1 == 2) { x[i][j] = 0; x[i][j + 1] = 1; x[i][j + 2] = 1; }
  94. if (v1 == 1) { x[i][j + 1] = -2; }
  95. }
  96. }
  97. if (p3 == 1) {
  98. if (j == 48) { x[i + 1][j] = Query(i + 1, j, i + 1, j); x[i + 1][j + 1] = 1 - x[i + 1][j]; }
  99. else {
  100. int v1 = Query(i + 1, j + 1, i + 1, j + 2);
  101. if (v1 == 0) { x[i + 1][j] = 1; x[i + 1][j + 1] = 0; x[i + 1][j + 2] = 0; }
  102. if (v1 == 2) { x[i + 1][j] = 0; x[i + 1][j + 1] = 1; x[i + 1][j + 2] = 1; }
  103. if (v1 == 1) { x[i + 1][j + 1] = -2; }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. inline void solve4(int row, int col, int p1) {
  111. int i = row, j = col;
  112. if (p1 == 0)return;
  113. int p2 = Query(i, j, i + 1, j + 3), p3 = p1 - p2;
  114. if (p2 == 0) {}
  115. 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; } } }
  116. if (p3 == 0) {}
  117. 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; } } }
  118. if (p2 >= 1 && p2 <= 7 && p3 >= 1 && p3 <= 7) {
  119. int p4 = Query(i, j, i + 3, j + 1), p5 = p1 - p4;
  120. if (p4 != 0 && p5 != 0) {
  121. int p10 = Query(i, j, i + 1, j + 1), p11 = p2 - p10;
  122. int p12 = p4 - p10, p13 = p5 - p11;
  123. solve2(i, j, p10); solve2(i, j + 2, p11);
  124. solve2(i + 2, j, p12); solve2(i + 2, j + 2, p13);
  125. }
  126. if (p4 == 0) {
  127. solve2(i, j, 0); solve2(i + 2, j, 0);
  128. solve2(i, j + 2, p2); solve2(i + 2, j + 2, p3);
  129. }
  130. else if (p5 == 0) {
  131. solve2(i, j, p2); solve2(i + 2, j, p3);
  132. solve2(i, j + 2, 0); solve2(i + 2, j + 2, 0);
  133. }
  134. }
  135. else {
  136. 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); }
  137. 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); }
  138. }
  139. }
  140. inline void saiki(int row, int col, int hs, int ws, int p1) {
  141. if (row >= 50 || col >= 50)return;
  142. if (hs == 2 && ws == 2) { solve2(row, col, p1); return; }
  143. if (hs == 4 && ws == 4) { solve4(row, col, p1); return; }
  144. if (hs > ws) {
  145. int E1 = p1;
  146. int EE1, EE2;
  147. if (E1 == hs*ws) { EE1 = ws*Div[hs]; EE2 = ws*(hs - Div[hs]); }
  148. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  149. else { EE1 = Query(row, col, row + Div[hs] - 1, col + ws - 1); EE2 = E1 - EE1; }
  150. saiki(row, col, Div[hs], ws, EE1);
  151. saiki(row + Div[hs], col, hs - Div[hs], ws, EE2);
  152. }
  153. else {
  154. int E1 = p1;
  155. int EE1, EE2;
  156. if (E1 == hs*ws) { EE1 = hs*Div[ws]; EE2 = hs*(ws - Div[ws]); }
  157. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  158. else { EE1 = Query(row, col, row + hs - 1, col + Div[ws] - 1); EE2 = E1 - EE1; }
  159. saiki(row, col, hs, Div[ws], EE1);
  160. saiki(row, col + Div[ws], hs, ws - Div[ws], EE2);
  161. }
  162. }
  163. int main() {
  164. //Init(1);
  165. for (int i = 0; i < 2500; i++)x[i / 50][i % 50] = -1;
  166. int H, W, N; cin >> H >> W >> N >> KK;
  167. for (int i = 1; i <= 50; i++) {
  168. if (i > 32)Div[i] = 32;
  169. else if (i > 16)Div[i] = 16;
  170. else if (i > 8)Div[i] = 8;
  171. else if (i > 4)Div[i] = 4;
  172. else if (i > 2)Div[i] = 2;
  173. else if (i > 1)Div[i] = 1;
  174. }
  175. saiki(0, 0, 50, 50, 250);
  176. for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { if (x[i][j] == -1)x[i][j] = 0; } }
  177. for (int i = 0; i < 50; i++) {
  178. for (int j = 48; j >= 0; j--) {
  179. if (x[i][j] == -2) {
  180. x[i][j] = 1 - x[i][j + 1];
  181. x[i][j - 1] = 1 - x[i][j];
  182. }
  183. }
  184. }
  185. int t=clock();
  186. while(clock()-t<=(KK%100)*1000){}
  187. //solve(x);
  188. cout << "! " << solve() << endl;
  189. return 0;
  190. }
Runtime error #stdin #stdout 0s 3484KB
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