Advertisement
erek1e

EGOI '23 - Find the Box

Jul 21st, 2023
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  7.     int h, w; cin >> h >> w;
  8.  
  9.     if (h <= 2) { // edge cases
  10.         for (int i = 0; i < h; ++i) {
  11.             cout << "? " << string(i, 'v') + string(w, '>') << endl;
  12.             int r, c; cin >> r >> c;
  13.             if (r != i) {
  14.                 cout << "! " << i << " 0" << endl;
  15.                 return 0;
  16.             }
  17.             else if (c != w-1) {
  18.                 cout << "! " << r << ' ' << c+1 << endl;
  19.                 return 0;
  20.             }
  21.         }
  22.     }
  23.  
  24.     string s;
  25.     for (int i = 0; i < h+1; ++i) s += string(w, '<') + "v" + string(w, '>') + "^>v";
  26.     cout << "? " << s << endl;
  27.     int r, c; cin >> r >> c;
  28.     if (r == h-1 && c == w-1) {
  29.         // either first row or square 1 0
  30.         cout << "? " << ">vv<^^" << string(w, '>') << endl;
  31.         cin >> r >> c;
  32.         if (r == 2) cout << "! 1 0" << endl;
  33.         else cout << "! 0 " << c+1 << endl;
  34.     } else {
  35.         // try first column
  36.         cout << "? " << string(h, 'v') << endl;
  37.         int r2, c2; cin >> r2 >> c2;
  38.         if (r2 != h-1) cout << "! " << r2+1 << " 0" << endl;
  39.         else cout << "! " << r+1 << ' ' << c << endl;
  40.     }
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement