#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
#define ld long double
using namespace std;
constexpr bool readit = 0;
vector<vector<vector<int>>> heights;
int N, M, K, Q, ogq;
int query(int x, int y, int z) {
if(x < 0 || x >= N || y < 0 || y >= M || z < 0 || z >= K) return -1;
if(heights[x][y][z] != -1) return heights[x][y][z];
if(!Q) return -1;
printf("? %d %d %d\n", x + 1, y + 1, z + 1);
fflush(stdout);
Q--;
int ans = -1;
(void)scanf("%d", &ans);
if (ans == -1) exit(0);
heights[x][y][z] = ans;
return ans;
}
bool tryit(int x, int y, int z) {
return (x == 0 || query(x, y, z) >= query(x - 1, y, z)) &&
(x == N - 1 || query(x, y, z) >= query(x + 1, y, z)) &&
(y == 0 || query(x, y, z) >= query(x, y - 1, z)) &&
(y == M - 1 || query(x, y, z) >= query(x, y + 1, z)) &&
(z == 0 || query(x, y, z) >= query(x, y, z - 1)) &&
(z == K - 1 || query(x, y, z) >= query(x, y, z + 1));
}
void guess(int x, int y, int z) {
x++, y++, z++;
printf("! %d %d %d\n", x, y, z);
x--, y--, z--;
if constexpr(readit) assert((x == 0 || heights[x][y][z] >= heights[x - 1][y][z]) &&
(x == N - 1 || heights[x][y][z] >= heights[x + 1][y][z]) &&
(y == 0 || heights[x][y][z] >= heights[x][y - 1][z]) &&
(y == M - 1 || heights[x][y][z] >= heights[x][y + 1][z]) &&
(z == 0 || heights[x][y][z] >= heights[x][y][z - 1]) &&
(z == K - 1 || heights[x][y][z] >= heights[x][y][z + 1]));
exit(0);
}
int main() {
(void)scanf("%d %d %d %d", &N, &M, &K, &Q);
ogq = Q;
heights.resize(N, vector<vector<int>>(M, vector<int>(K, -1)));
if constexpr(readit) rep(i, 0, N) rep(j, 0, M) rep(k, 0, K) scanf("%d", &heights[i][j][k]);
mt19937 rnd(2137 * N + Q);
array<int, 4> mx = {{-1, 0, 0, 0}};
while(Q * 2 > ogq) {
int x = rnd() % N, y = rnd() % M, z = rnd() % K;
mx = max(mx, {{query(x, y, z), x, y, z}});
if(ogq - Q == N * M * K) break;
}
int x = mx[1], y = mx[2], z = mx[3];
while(Q) {
mx = max(mx, {{query(x + 1, y, z), x + 1, y, z}});
if(!Q) break;
mx = max(mx, {{query(x - 1, y, z), x - 1, y, z}});
if(!Q) break;
mx = max(mx, {{query(x, y + 1, z), x, y + 1, z}});
if(!Q) break;
mx = max(mx, {{query(x, y - 1, z), x, y - 1, z}});
if(!Q) break;
mx = max(mx, {{query(x, y, z + 1), x, y, z + 1}});
if(!Q) break;
mx = max(mx, {{query(x, y, z - 1), x, y, z - 1}});
if(mx[0] == query(x, y, z)) break;
x = mx[1], y = mx[2], z = mx[3];
}
guess(x, y, z);
}
Compilation message (stderr)
worm.cpp: In function 'int query(int, int, int)':
worm.cpp:32:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | (void)scanf("%d", &ans);
| ~~~~~^~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:61:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | (void)scanf("%d %d %d %d", &N, &M, &K, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |