Submission #1358364

#TimeUsernameProblemLanguageResultExecution timeMemory
1358364julia_08Find the Box (EGOI23_findthebox)C++20
100 / 100
0 ms456 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m;

void answer(int x, int y){
  cout << "! " << x - 1 << " " << y - 1 << endl;
}

pair<int, int> ask(string s){

  cout << "? " << s << endl;

  int x, y; cin >> x >> y;
  return {x + 1, y + 1};

}

string build_row(int col){

  string to_ask = "";

  for(int i=0; i<(col - 1); i++) to_ask.push_back('>');

  for(int i=0; i<(n - 1); i++) to_ask.push_back('v');

  return to_ask;

}

int find_row(int col){

  auto [x, y] = ask(build_row(col));

  if(y != col) return 1;
  return x + 1;

}

int main(){
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> m;

  string q_r = "";

  int mid = m / 2 + 1;
  int sz = m - mid + 1;

  for(int i=0; i<(mid - 1); i++) q_r.push_back('>');

  for(int i=0; i<n; i++){
    
    for(int j=0; j<(sz - 1); j++) q_r.push_back('>');
    for(int j=0; j<(sz - 1); j++) q_r.push_back('<');

    if(i < n - 1) q_r.push_back('v');  

  }

  auto [x1, y1] = ask(q_r);

  if(make_pair(x1, y1) == make_pair(n, mid)){

    string q_l = "";

    for(int i=0; i<(mid - 1); i++) q_l.push_back('>');

    for(int i=0; i<(n - 1); i++){

      q_l.push_back('v');

      for(int j=0; j<(mid - 2); j++) q_l.push_back('<');
      for(int j=0; j<(mid - 2); j++) q_l.push_back('>');

    }

    for(int i=0; i<(mid - 1); i++) q_l.push_back('<');

    for(int i=0; i<(n - 1); i++) q_l.push_back('^');

    auto [x, y] = ask(q_l);

    if(x == 1){
      answer(n, y - 1);
    } else answer(x - 1, y);
    
    return 0;
    
  }

  if(y1 == mid){
    answer(x1 + 1, y1);
    return 0;
  }

  if(y1 > 1){
    answer(find_row(y1 + sz), y1 + sz);
    return 0;
  }

  auto [x, y] = ask(build_row(mid + 1));

  if(y < mid){
    answer(1, y + 1);
    return 0;
  }

  if(y < mid + 1) x = 0;
  answer(x + 1, mid + 1);

  return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...