#include <bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1LL<<30;
mt19937 rng;
vector<int> dx = {0,0,0,0,-1,1};
vector<int> dy = {0,0,-1,1,0,0};
vector<int> dz = {-1,1,0,0,0,0};
int n,m,k,q;
int qcount = 0;
int debug = 0;
vector<vector<vector<int>>> humidity;
vector<vector<int>> neighbours(vector<int> point) {
vector<vector<int>> ans;
for (int dir=0; dir<6; dir++) {
int nx,ny,nz; nx=point[0]+dx[dir]; ny=point[1]+dy[dir]; nz=point[2]+dz[dir];
if (!(1<=nx && nx<=n && 1<=ny && ny<=m && 1<=nz && nz<=k)) {
continue;
}
ans.push_back({nx,ny,nz});
}
return ans;
}
map<vector<int>,int> cache;
int query(int x, int y, int z) {
if (!(1<=x && x<=n && 1<=y && y<=m && 1<=z && z<=k)) {
return -1;
}
if (cache.count({x,y,z})) return cache[{x,y,z}];
cout << "? " << x <<" " << y <<" " <<z << endl;
qcount++;
if (qcount>=q-1) {
while (1==1) {
cout << qcount << endl;
int o=0;
}
}
int an;
if (!debug) {
cin >> an;
}
else {
cout << humidity[x-1][y-1][z-1] << endl;
return cache[{x,y,z}] = humidity[x-1][y-1][z-1];
}
return cache[{x,y,z}] = an;
}
void answer(int x, int y, int z) {
cout << "! " << x << " " << y << " " << z << endl;
if (debug) {
cout << "in " << qcount <<" " << "queries" << endl;
int gg=0;
for (auto j:neighbours({x,y,z})) {
if (humidity[j[0]-1][j[1]-1][j[2]-1]>humidity[x-1][y-1][z-1]) {
gg=1;
}
}
if (gg) {
cout << "INCORRECT" << endl;
}
else {
cout << "CORRECT" << endl;
}
}
}
signed main() {
rng.discard((time(NULL))%100000);
cin >> n >> m >> k >> q;
if (debug) humidity = vector<vector<vector<int>>>(n,vector<vector<int>>(m,vector<int>(k,0)));
if (debug) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
for (int k1=0; k1<k; k1++) {
humidity[i][j][k1]=rng()%10000;
cout << humidity[i][j][k1] <<" ";
}
}
cout << endl;
}
}
int lx,rx,ly,ry;
int answered = 0;
lx = 1; rx = n; ly = 1; ry = m;
while (lx<rx || ly<ry) {
if (debug) cout << "binsearch " << lx <<" " << rx <<" " << ly <<" " << ry << endl;
if (rx-lx<ry-ly) {
//split by x
int mx = (lx+rx)/2;
int ma = -1;
int mi = -1;
for (int y=ly; y<=ry; y++) {
if (query(mx,y,1)>ma) {
ma = query(mx,y,1);
mi = y;
}
}
if (query(mx+1,mi,1)>query(mx,mi,1)) {
//go down
lx=mx+1;
}
else if (query(mx-1,mi,1)>query(mx,mi,1)) {
rx = mx-1;
}
else {
answer(mx,mi,1); answered = 1;
break;
}
}
else {
//split by y
int my = (ly+ry)/2;
int ma = -1;
int mi = -1;
for (int x=lx; x<=rx; x++) {
if (query(x,my,1)>ma) {
ma = query(x,my,1);
mi = x;
}
}
if (query(mi,my+1,1)>query(mi,my,1)) {
//go down
ly=my+1;
}
else if (query(mi,my-1,1)>query(mi,my,1)) {
ry=my-1;
}
else {
answer(mi,my,1); answered = 1;
break;
}
}
}
if (!answered) {
answer(lx,ly,1);
}
}
Compilation message
worm.cpp: In function 'long long int query(long long int, long long int, long long int)':
worm.cpp:39:17: warning: unused variable 'o' [-Wunused-variable]
39 | int o=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
69 ms |
1316 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
812 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
6 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
548 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Runtime error |
24 ms |
600 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
344 KB |
not a local maximum |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
32 ms |
848 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Incorrect |
3 ms |
456 KB |
not a local maximum |
5 |
Halted |
0 ms |
0 KB |
- |