Submission #469822

#TimeUsernameProblemLanguageResultExecution timeMemory
469822OzyWorm Worries (BOI18_worm)C++17
0 / 100
31 ms8584 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define MAX 1000 lli n,m,k,q; pair<lli,lli> res; lli dir[8] = {-1,0,1,0,0,1,0,-1}; lli arr[MAX+2][MAX+2]; lli query(lli x, lli y) { cout << "? " << x << ' ' << y << " 1" << endl; lli a; cin >> a; return a; } pair<lli,lli> checa(pair<lli,lli> coord) { lli sector,val = arr[coord.first][coord.second]; pair<lli,lli> nuevo; rep(i,0,3) { nuevo = coord; nuevo.first += dir[i]; nuevo.second += dir[i+4]; if (nuevo.first == 0 || nuevo.first == n+1) continue; if (nuevo.second == 0 || nuevo.second == m+1) continue; if (arr[nuevo.first][nuevo.second] == 0) arr[nuevo.first][nuevo.second] = query(nuevo.first, nuevo.second); if (arr[nuevo.first][nuevo.second] > val) { val = arr[nuevo.first][nuevo.second]; sector = i; } } if (val == arr[coord.first][coord.second]) return{-1,0}; return {val,sector}; } pair<lli,lli> binaria(lli ifil, lli ffil, lli icol, lli fcol) { lli mitadf, updown, mitadc,ant,mayor = 0; pair<lli,lli> coord; if (ifil == ffil && icol == fcol) return {ifil,icol}; mitadc = (icol+fcol)/2; rep(i,ifil,ffil) { if (arr[i][mitadc] == 0) arr[i][mitadc] = query(i,mitadc); if (arr[i][mitadc] > mayor) { mayor = arr[i][mitadc]; coord = {i,mitadc}; } } pair<lli,lli> x = checa(coord); if (x.first == -1) return coord; if (x.second == 1) icol = mitadc+1; else fcol = mitadc-1; ant = mayor; mitadf = (ifil+ffil)/2; rep(i,icol,fcol) { if (arr[mitadf][i] == 0) arr[mitadf][i] = query(mitadf,i); if (arr[mitadf][i] > mayor) { mayor = arr[mitadf][i]; coord = {mitadf,i}; } } if (mayor == ant){ if (coord.first > mitadf) ifil = mitadf+1; else ffil = mitadf-1; } else { pair<lli,lli> y = checa(coord); if (y.first == -1) return coord; if (y.second == 0) ffil = mitadf-1; else ifil = mitadf+2; } return binaria(ifil,ffil,icol,fcol); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k >> q; res = binaria(1,n,1,m); cout << "! " << res.first << ' ' << res.second << " 1"; }

Compilation message (stderr)

worm.cpp: In function 'std::pair<long long int, long long int> binaria(long long int, long long int, long long int, long long int)':
worm.cpp:53:17: warning: unused variable 'updown' [-Wunused-variable]
   53 |     lli mitadf, updown, mitadc,ant,mayor = 0;
      |                 ^~~~~~
worm.cpp: In function 'std::pair<long long int, long long int> checa(std::pair<long long int, long long int>)':
worm.cpp:47:23: warning: 'sector' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     return {val,sector};
      |                       ^
#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...