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 (p2 == 1) { x[i][j] = Query(i, j, i, j); x[i][j + 1] = 1 - x[i][j]; }
  30. if (p3 == 0) { x[i + 1][j] = 0; x[i + 1][j + 1] = 0; }
  31. if (p3 == 2) { x[i + 1][j] = 1; x[i + 1][j + 1] = 1; }
  32. if (p3 == 1) { x[i + 1][j] = Query(i + 1, j, i + 1, j); x[i + 1][j + 1] = 1 - x[i + 1][j]; }
  33. }
  34. }
  35. inline void saiki(int row, int col, int hs, int ws, int p1) {
  36. if (row >= 50 || col >= 50)return;
  37. if (hs == 2 && ws == 2) { solve2(row, col, p1); return; }
  38. if (hs > ws) {
  39. int E1 = p1;
  40. int EE1, EE2;
  41. if (E1 == hs*ws) { EE1 = ws*Div[hs]; EE2 = ws*(hs - Div[hs]); }
  42. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  43. else { EE1 = Query(row, col, row + Div[hs] - 1, col + ws - 1); EE2 = E1 - EE1; }
  44. saiki(row, col, Div[hs], ws, EE1);
  45. saiki(row + Div[hs], col, hs - Div[hs], ws, EE2);
  46. }
  47. else {
  48. int E1 = p1;
  49. int EE1, EE2;
  50. if (E1 == hs*ws) { EE1 = hs*Div[ws]; EE2 = hs*(ws - Div[ws]); }
  51. else if (E1 == 0) { EE1 = 0; EE2 = 0; }
  52. else { EE1 = Query(row, col, row + hs - 1, col + Div[ws] - 1); EE2 = E1 - EE1; }
  53. saiki(row, col, hs, Div[ws], EE1);
  54. saiki(row, col + Div[ws], hs, ws - Div[ws], EE2);
  55. }
  56. }
  57. int main() {
  58. int H, W, N; cin >> H >> W >> N>>K;
  59. for (int i = 1; i <= 50; i++) {
  60. if (i > 32)Div[i] = 32;
  61. else if (i > 16)Div[i] = 16;
  62. else if (i > 8)Div[i] = 8;
  63. else if (i > 4)Div[i] = 4;
  64. else if (i > 2)Div[i] = 2;
  65. else if (i > 1)Div[i] = 1;
  66. }
  67. saiki(0, 0, 50, 50, 250);
  68. cout << "! " << solve() << endl;
  69. return 0;
  70. }
Runtime error #stdin #stdout 0s 3476KB
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 3 1
? 0 0 1 1
? 0 0 0 1
? 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 35 1
? 32 0 33 1
? 32 0 32 1
? 32 16 47 31
? 32 16 47 23
? 32 16 39 23
? 32 16 39 19
? 32 16 35 19
? 32 16 35 17
? 32 16 33 17
? 32 16 32 17
? 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 3 33
? 0 32 1 33
? 0 32 0 33
? 16 32 31 47
? 16 32 31 39
? 16 32 23 39
? 16 32 23 35
? 16 32 19 35
? 16 32 19 33
? 16 32 17 33
? 16 32 16 33
? 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 35 33
? 32 32 33 33
? 32 32 32 33
? 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