제출 #716051

#제출 시각아이디문제언어결과실행 시간메모리
716051Charizard2021Worm Worries (BOI18_worm)C++17
23 / 100
977 ms276 KiB
#include <iostream> #include <vector> #include <cmath> #include <cstdlib> using namespace std; int n, m, k, maxq; int value(int x, int y, int z){ if(x <= 0 || x > n || y <= 0 || y > m || z <= 0 || z > k) return 0; cout << "? " << x << ' ' << y << ' ' << z << endl; int ans; cin >> ans; if (ans == -1) exit(0); return ans; } int dx[] = {1, -1, 0, 0, 0, 0}; int dy[] = {0, 0, 1, -1, 0, 0}; int dz[] = {0, 0, 0, 0, 1, -1}; int main(){ srand(561); cin >> n >> m >> k >> maxq; int samples = 100000; // I'm feeling lucky int record = 0; int x, y, z; for(int i=0; i<samples; ++i){ int a = 1+rand()%n, b = 1+rand()%m, c = 1+rand()%k; int res = value(a, b, c); if(res > record){ record = res; x = a, y = b, z = c; } } vector<bool> tried(6, false); foo: int left = 0; for(int i=0; i<6; ++i) left += (int)!tried[i]; if(left == 0){ cout << "! " << x << ' ' << y << ' ' << z << endl; return 0; } int r = rand() % left; for(int i=0; i<6; ++i) if(!tried[i]){ if(r == 0){ int x1 = x + dx[i], y1 = y + dy[i], z1 = z + dz[i]; int res = value(x1, y1, z1); if(res > record){ record = res; x = x1; y = y1; z = z1; for(int j=0; j<6; ++j) tried[j] = false; tried[i ^ 1] = true; goto foo; } else { tried[i] = true; goto foo; } } --r; } }

컴파일 시 표준 에러 (stderr) 메시지

worm.cpp: In function 'int main()':
worm.cpp:55:43: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |   cout << "! " << x << ' ' << y << ' ' << z << endl;
      |                                           ^
worm.cpp:55:36: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |   cout << "! " << x << ' ' << y << ' ' << z << endl;
      |                                    ^~~
worm.cpp:55:24: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |   cout << "! " << x << ' ' << y << ' ' << z << endl;
      |                        ^~~
#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...