Submission #1259540

#TimeUsernameProblemLanguageResultExecution timeMemory
1259540patgraWorm Worries (BOI18_worm)C++20
0 / 100
222 ms500448 KiB
#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 = 1; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; constexpr bool readit = 0; vector<vector<vector<int>>> heights; int N, M, K, Q; int query(int x, int y, int z) { 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; } void guess(int x, int y, int z) { x++, y++, z++; printf("! %d %d %d\n", x, y, z); exit(0); } int main() { (void)scanf("%d %d %d %d", &N, &M, &K, &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]); int x = 0, y = 0, z = 0; double lr = N * 3 / 2.0, alpha = 0.95; bool found = false; while(!found) { int nx = x, ny = y, nz = z; int dl = x == 0 ? 0 : max(0, query(x - 1, y, z) - query(x, y, z)); int dr = x == N - 1 ? 0 : max(0, query(x + 1, y, z) - query(x, y, z)); if(dl > dr) nx -= (int)ceil((lr * (double)dl)); else nx += (int)ceil((lr * (double)dr)); dl = y == 0 ? 0 : max(0, query(x, y - 1, z) - query(x, y, z)); dr = y == M - 1 ? 0 : max(0, query(x, y + 1, z) - query(x, y, z)); if(dl > dr) ny -= (int)ceil((lr * (double)dl)); else ny += (int)ceil((lr * (double)dr)); dl = z == 0 ? 0 : max(0, query(x, y, z - 1) - query(x, y, z)); dr = z == K - 1 ? 0 : max(0, query(x, y, z + 1) - query(x, y, z)); if(dl > dr) nz -= (int)ceil((lr * (double)dl)); else nz += (int)ceil((lr * (double)dr)); nx = min(max(0, nx), N - 1); ny = min(max(0, ny), M - 1); nz = min(max(0, nz), K - 1); if(x == nx && y == ny && z == nz) found = true; x = nx, y = ny, z = nz; lr *= alpha; } guess(x, y, z); }

Compilation message (stderr)

worm.cpp: In function 'int query(int, int, int)':
worm.cpp:30:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         (void)scanf("%d", &ans);
      |               ~~~~~^~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:43:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         (void)scanf("%d %d %d %d", &N, &M, &K, &Q);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...