#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <chrono>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <bitset>
#include <cmath>
#include <cassert>
typedef long long ll;
typedef long double ld;
using namespace std;
const int logn = 31;
int n, cx, cy, xo, yo, qu = 0;
vector<vector<int> > h;
bool query(int i, int num)
{
int x, y;
if (num == 0) x = i, y = yo;
if (num == 1) x = xo, y = i;
if (x < 1 || y < 1 || x > n || y > n) return false;
qu++;
if (qu > 300)
{
cout << "solution " << 1 << " " << 1 << endl;
exit(0);
}
cout << "examine " << x << " " << y << endl;
//return h[x][y];
string s;
cin >> s;
return s == "true";
}
int find_last(int l, int r, int good, int num) // najdeme posledne policko, ktore ma farbu l
{
while (l < r)
{
int m = (l + r + 1) / 2;
if (query(m, num) == good)
l = m;
else
r = m - 1;
}
return l;
}
int k = -1;
int find_one(int i0, int num)
{
int lw = i0, rw = i0;
for (int b = 0; b < logn; b++)
{
int i = i0 - min(1 << b, i0);
if (lw == i0 && !query(i, num)) lw = i;
i = i0 + min(1 << b, n + 1 - i0);
if (rw == i0 && !query(i, num)) rw = i;
}
if (lw == i0) lw = 0;
if (rw == i0) rw = n + 1;
int lb = find_last(lw, i0, 0, num) + 1;
int rb = k == -1 ? find_last(i0, rw, 1, num) : lb + k - 1;
k = rb - lb + 1;
int first = lb;
while (query(first - 2 * k, num)) first -= 2 * k;
int last = rb;
while (query(last + 2 * k, num)) last += 2 * k;
return (last + first) / 2;
}
int main()
{
cin >> n;
cin >> xo >> yo;
/*cin >> cx >> cy;
h.assign(n + 1, vector<int>(n + 1));
int xf = cx - (5 * k) / 2, yf = cy - (5 * k) / 2;
for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) if ((i + j) % 2 == 0)
{
for (int x = xf + i * k; x < xf + (i + 1) * k; x++) for (int y = yf + j * k; y < yf + (j + 1) * k; y++)
{
h[x][y] = 1;
}
}*/
int xc = find_one(xo, 0);
int yc = find_one(yo, 1);
cout << "solution " << xc << " " << yc << endl;
return 0;
}
Compilation message
aliens.cpp: In function 'bool query(int, int)':
aliens.cpp:24:9: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | int x, y;
| ^
aliens.cpp:24:6: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
24 | int x, y;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
200 KB |
Output is correct |
2 |
Incorrect |
3 ms |
200 KB |
too many queries |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Output is correct |
2 |
Incorrect |
3 ms |
200 KB |
too many queries |
3 |
Halted |
0 ms |
0 KB |
- |