답안 #759943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759943 2023-06-17T05:46:56 Z gun_gan Aliens (IOI07_aliens) C++17
100 / 100
2 ms 208 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// kanan, atas, kiri, bawah
 
ll N, X, Y;
ll xMin, xMax, yMin, yMax;
ll x = 0, y = 0, m = 0;
 
bool can(ll x, ll y) {
      if(x <= 0 || x > N || y <= 0 || y > N) return 0;
      cout << "examine " << x << " " << y << endl;
 
      string s;
      cin >> s;
 
      return s == "true"; 
}
 
void work(int k) {
      ll l = 1, r = 1e9, res = 0;

      while(l <= r) {
            ll mid = (l + r) >> 1;

            if(can(x + 2 * mid * m * dx[k], y + 2 * mid * m * dy[k])) {
                  l = mid + 1, res = mid;
            } else {
                  r = mid - 1;
            }
      }
      
      xMin = min(xMin, x + 2 * m * res * dx[k]);
      xMax = max(xMax, x + 2 * m * res * dx[k]);

      yMin = min(yMin, y + 2 * m * res * dy[k]);
      yMax = max(yMax, y + 2 * m * res * dy[k]);     
}
 
int main() {
      ios_base::sync_with_stdio(0); cin.tie(0);
 
      cin >> N >> X >> Y;
      
      // 60
      for(int k = 1, curx = X + k; ; k <<= 1, curx += k) {
            if(!can(curx, Y)) {
                  ll l = curx - k, r = curx - 1, res = 0;
                  while(l <= r) {
                        ll m = (l + r) >> 1;
                        if(can(m, Y)) {
                              l = m + 1, res = m;
                        } else {
                              r = m - 1;
                        }
                  }
                  x += res;
                  m += res;
                  break;
            }
      }

      // 60
      for(int k = 1, curx = X - k; ; k <<= 1, curx -= k) {
            if(!can(curx, Y)) {
                  ll l = curx + 1, r = curx + k, res = 0;
                  while(l <= r) {
                        ll m = (l + r) >> 1;
                        if(can(m, Y)) {
                              r = m - 1, res = m;
                        } else {
                              l = m + 1;
                        }
                  }
                  x += res;
                  m -= res;
                  break;
            }
      }

      x /= 2;
      m++;

      // 60
      for(int k = 1, cury = Y + k; ; k <<= 1, cury += k) {
            if(!can(X, cury)) {
                  ll l = cury - k, r = cury - 1, res = 0;
                  while(l <= r) {
                        ll m = (l + r) >> 1;
                        if(can(X, m)) {
                              l = m + 1, res = m;
                        } else {
                              r = m - 1;
                        }
                  }

                  y = ((res - m + 1) + res) / 2;
                  break;
            }
      }

      // cout << "cek m : " << m << " (x, y) = " << x << " " << y << endl;

      xMin = xMax = x;
      yMin = yMax = y;

      // 30
      work(0);
      // 30
      work(1);
      // 30
      work(2);
      // 30
      work(3);

      // cout << xMin << " " << xMax << " " << yMin << " " << yMax << '\n';

      cout << "solution " << (xMin + xMax) / 2 << " " << (yMin + yMax) / 2 << endl;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct