Advertisement
willy108

Cloyster

Aug 2nd, 2022
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. //weinerschitzel
  2.  
  3. //https://codeforces.com/gym/102341/problem/C
  4. //
  5.  
  6. //misaka and elaina will carry me to master
  7. #include <iostream>
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <cmath>
  11. #include <utility>
  12. #include <cassert>
  13. #include <algorithm>
  14. #include <vector>
  15. #include <functional>
  16. #include <numeric>
  17. #include <set>
  18. #include <array>
  19. #include <queue>
  20. #include <map>
  21. #include <chrono>
  22. #include <random>
  23.  
  24. #define ll long long
  25. #define lb long double
  26. #define sz(vec) ((int)(vec.size()))
  27. #define all(x) x.begin(), x.end()
  28. #define pb push_back
  29. #define mp make_pair
  30. #define kill(x, s) {int COND = x; if(COND){ cout << s << "\n"; return ; }}
  31.  
  32. #ifdef ONLINE_JUDGE
  33. #define cerr while(0) cerr
  34. #endif
  35.  
  36. const lb eps = 1e-9;
  37. const ll mod = 1e9 + 7, ll_max = 1e18;
  38. //const ll mod = (1 << (23)) * 119 +1, ll_max = 1e18;
  39. const int MX = 2e3 +10, int_max = 0x3f3f3f3f;
  40.  
  41. struct {
  42.   template<class T>
  43.   operator T() {
  44.     T x; std::cin >> x; return x;
  45.   }
  46. } in;
  47.  
  48. using namespace std;
  49.  
  50. mt19937 rng(3366);
  51.  
  52. int n;
  53.  
  54. int arr[MX][MX];
  55. int op;
  56. int query(int x, int y){
  57.     if(x < 0 || y < 0 || x >= n || y >= n) return 0;
  58.  
  59.     if(arr[x][y]) return arr[x][y];
  60.     op++;
  61.     cout << "? " <<  x+1 << " " << y+1 << endl;
  62.     int a; cin >> a;
  63.     //int a = rng()%(1000000000);
  64.     return arr[x][y] = a;
  65. }
  66.  
  67.  
  68. int mxin(int a, int b, int c, int d){
  69.         int ans = 0;
  70.     for(int i = a; i<b; i++){
  71.         for(int j = c; j<d; j++){
  72.             ans = max(ans, arr[i][j]);
  73.         }
  74.     }
  75.     return ans;
  76. }
  77.  
  78. void go(int a, int b, int c, int d){
  79.     if(a + 1 == b && c + 1 == d){
  80.         assert(op <= n*3 +210);
  81.         cout << "! " << a+1 << " " << c+1 << endl;
  82.         return ;
  83.     }
  84.     int m1 = (a + b)/2, m2 = (c + d)/2;
  85.     if(b - a > d - c){ //split the longer one
  86.         int best = c;
  87.         for(int i = c; i<d; i++){
  88.             if(query(m1, i) > query(m1, best)){
  89.                 best = i;
  90.             }
  91.         }
  92.         for(int i = -1; i<=1; i++){
  93.             for(int j = -1; j<=1; j++){
  94.                 query(m1 + i, best + j);
  95.             }
  96.         }
  97.         if(mxin(a, m1, c, d) > mxin(m1, b, c, d)){
  98.             go(a, m1, c, d);
  99.         }else{
  100.             go(m1, b, c, d);
  101.         }
  102.     }else{
  103.         int best = a;
  104.         for(int i = a; i<b; i++){
  105.             if(query(i, m2) >= query(best, m2)){
  106.                 best = i;
  107.             }
  108.         }
  109.         for(int i = -1; i<=1; i++){
  110.             for(int j = -1; j<=1; j++){
  111.                 query(best + i, m2 + j);
  112.             }
  113.         }  
  114.         if(mxin(a, b, c, m2) > mxin(a, b, m2, d)){
  115.             go(a, b, c, m2);
  116.         }else{
  117.             go(a, b, m2, d);
  118.         }
  119.     }
  120. }
  121.  
  122. void solve(){
  123.     cin >> n;
  124.     go(0, n, 0, n);
  125. }
  126.  
  127. signed main(){
  128.   cin.tie(0) -> sync_with_stdio(0);
  129.  
  130.   int T = 1;
  131.   //cin >> T;
  132.   for(int i = 1; i<=T; i++){
  133.         solve();
  134.     }
  135.   return 0;
  136. }
  137.  
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement