Submission #1259552

#TimeUsernameProblemLanguageResultExecution timeMemory
1259552patgraWorm Worries (BOI18_worm)C++20
Compilation error
0 ms0 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 #define ld long double 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; ld lr = N * 3 / 2.0, alpha = 0.9; 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)); dl = min(dl, 1); dr = min(dr, 1); if(dl > dr) nx -= (int)ceil((lr * (ld)dl)); else nx += (int)ceil((lr * (ld)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)); dl = min(dl, 1); dr = min(dr, 1); if(dl > dr) ny -= (int)ceil((lr * (ld)dl)); else ny += (int)ceil((lr * (ld)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)); dl = min(dl, 1); d#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 #define ld long double 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; ld lr = N * 3 / 2.0, alpha = 0.9; 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 * (ld)min(1, dl))); else nx += (int)ceil((lr * (ld)min(1, 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 * (ld)min(1, dl))); else ny += (int)ceil((lr * (ld)min(1, 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 * (ld)min(1, dl))); else nz += (int)ceil((lr * (ld)min(1, 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); } r = min(dr, 1); if(dl > dr) nz -= (int)ceil((lr * (ld)dl)); else nz += (int)ceil((lr * (ld)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:71:10: error: stray '#' in program
   71 |         d#include <bits/stdc++.h>
      |          ^
worm.cpp: In function 'int main()':
worm.cpp:71:9: error: 'd' was not declared in this scope; did you mean 'dr'?
   71 |         d#include <bits/stdc++.h>
      |         ^
      |         dr
worm.cpp:94:32: error: a function-definition is not allowed here before '{' token
   94 | int query(int x, int y, int z) {
      |                                ^
worm.cpp:107:33: error: a function-definition is not allowed here before '{' token
  107 | void guess(int x, int y, int z) {
      |                                 ^
worm.cpp:113:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  113 | int main() {
      |         ^~
worm.cpp:113:9: note: remove parentheses to default-initialize a variable
  113 | int main() {
      |         ^~
      |         --
worm.cpp:113:9: note: or replace parentheses with braces to value-initialize a variable
worm.cpp:113:12: error: a function-definition is not allowed here before '{' token
  113 | int main() {
      |            ^
worm.cpp:149:1: error: 'r' was not declared in this scope
  149 | r = min(dr, 1);
      | ^
worm.cpp: In function 'int query(int, int, int)':
worm.cpp:31:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         (void)scanf("%d", &ans);
      |               ~~~~~^~~~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:44:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         (void)scanf("%d %d %d %d", &N, &M, &K, &Q);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~