제출 #716079

#제출 시각아이디문제언어결과실행 시간메모리
716079Charizard2021Worm Worries (BOI18_worm)C++17
49 / 100
751 ms288 KiB
#include<bits/stdc++.h> 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(){ cin >> n >> m >> k >> maxq; if(m != 1 || k != 1){ int samples = maxq / 2; int record = 0; int x = -1, y = -1, z = -1; for(int i = 0; i < samples; i++){ int a = 1 + rand() % n; int b = 1 + rand() % m; int c = 1 + rand() % k; int res = value(a, b, c); if(res > record){ record = res; x = a, y = b, z = c; } } int walked = 0; vector<bool> tried(6, false); while (true) { 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]; int y1 = y + dy[i]; int 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; walked++; break; } else { tried[i] = true; break; } } r--; } } } } else{ int a = sqrt(n); int mx = 0, pos; for(int cur = 1; cur <= n; cur += a){ cout << "? " << cur << " 1 1" << endl; int res; cin >> res; if (res == -1){ exit(0); } if(res > mx){ mx = res; pos = cur; } } int low, high; while(true){ low = -1; high = -1; if(pos >= 2){ cout << "? " << pos - 1 << " 1 1" << endl; cin >> low; if (low == -1){ exit(0); } } if(pos + 1 <= n){ cout << "? " << pos + 1 << " 1 1" << endl; cin >> high; if (high == -1){ exit(0); } } if(low > mx){ mx = low; pos = pos - 1; } if(high > mx){ mx = high; pos = pos + 1; } cout << "! " << pos << " 1 1" << endl; } } }

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

worm.cpp: In function 'int main()':
worm.cpp:104:44: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  104 |                 cout << "? " << pos + 1 << " 1 1" << 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...