Submission #441595

#TimeUsernameProblemLanguageResultExecution timeMemory
441595Haruto810198Worm Worries (BOI18_worm)C++17
32 / 100
471 ms992480 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d)) #define szof(x) ((int)(x).size()) #define vi vector<int> #define pii pair<int,int> #define F first #define S second #define pb push_back #define eb emplace_back #define mkp make_pair const int INF = 2147483647; const int LNF = INF*INF; const int MOD = 1000000007; const int mod = 998244353; const double phi = (sqrt(5) + 1) / 2.0; //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") int X, Y, Z; int Q; vector<vector<vi>> arr; int gMax; int gMax_x, gMax_y; int query(int x, int y, int z){ int ret; if(x<=0 or x>=X+1 or y<=0 or y>=Y+1 or z<=0 or z>=Z+1){ return 0; } if(Q == 0){ return -1; } if(arr[x][y][z] == 0){ Q--; cout<<"? "<<x<<" "<<y<<" "<<z<<endl; cin>>ret; arr[x][y][z] = ret; } else{ ret = arr[x][y][z]; } if(ret > gMax){ gMax = ret; gMax_x = x; gMax_y = y; } return ret; } int solve_1D(int L, int R, int mid){ //cerr<<"solve("<<L<<", "<<R<<", "<<mid<<") "<<endl; if(L == R) return L; int ml = L + floor((R-L) * (2-phi)); int mr = R - floor((R-L) * (2-phi)); //assert(ml <= mr); if( mid*2 < L+R ){ ml = mid; } else{ mr = mid; } //assert(ml <= mr); int vl = query(ml, 1, 1); int vr = query(mr, 1, 1); if(vl > vr){ return solve_1D(L, mr - 1, ml); } else{ return solve_1D(ml + 1, R, mr); } } bool isMax(int x, int y, int z){ bool ret = 1; FOR(i, -1, 1, 2){ FOR(j, -1, 1, 2){ FOR(k, -1, 1, 2){ if( query(x, y, z) < query(x+i, y+j, z+k) ){ ret = 0; } } } } return ret; } pii solve_2D(int xL, int xR, int yL, int yR){ //cerr<<"solve("<<xL<<", "<<xR<<", "<<yL<<", "<<yR<<")"<<endl; if(xR-xL<=1 and yR-yL<=1){ FOR(i, xL, xR, 1){ FOR(j, yL, yR, 1){ if(isMax(i, j, 1)){ return mkp(i, j); } } } } if(xR-xL > yR-yL){ /// cut x int xmid = (xL + xR) / 2; int Max = -INF, pos_y; FOR(i, yL, yR, 1){ int tmp = query(xmid, i, 1); if(tmp > Max){ Max = tmp; pos_y = i; } } int vl = query(xmid-1, pos_y, 1); int vr = query(xmid+1, pos_y, 1); if(Max>=vl and Max>=vr){ return mkp(xmid, pos_y); } else if(gMax_x <= xmid){ return solve_2D(xL, xmid, yL, yR); } else{ return solve_2D(xmid, xR, yL, yR); } } else{ /// cut y int ymid = (yL + yR) / 2; int Max = -INF, pos_x; FOR(i, xL, xR, 1){ int tmp = query(i, ymid, 1); if(tmp > Max){ Max = tmp; pos_x = i; } } int vl = query(pos_x, ymid-1, 1); int vr = query(pos_x, ymid+1, 1); if(Max>=vl and Max>=vr){ return mkp(pos_x, ymid); } else if(gMax_y <= ymid){ return solve_2D(xL, xR, yL, ymid); } else{ return solve_2D(xL, xR, ymid, yR); } } } signed main(){ //ios_base::sync_with_stdio(false); //cin.tie(0); //cout.tie(0); cin>>X>>Y>>Z>>Q; arr.resize(X + 1); for(auto& i : arr){ i.resize(Y + 1); for(auto& j : i){ j.resize(Z + 1); } } if(Y==1 and Z==1){ int res = solve_1D(1, X, 1 + (X-1)*(phi-1)); cout<<"! "<<res<<" 1 1"<<endl; } else if(Z==1){ gMax = -INF; pii res = solve_2D(1, X, 1, Y); cout<<"! "<<res.F<<" "<<res.S<<" 1"<<endl; } else{ } return 0; }

Compilation message (stderr)

worm.cpp: In function 'std::pair<long long int, long long int> solve_2D(long long int, long long int, long long int, long long int)':
worm.cpp:42:5: warning: 'pos_x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     if(x<=0 or x>=X+1 or y<=0 or y>=Y+1 or z<=0 or z>=Z+1){
      |     ^~
worm.cpp:164:25: note: 'pos_x' was declared here
  164 |         int Max = -INF, pos_x;
      |                         ^~~~~
worm.cpp:137:25: warning: 'pos_y' may be used uninitialized in this function [-Wmaybe-uninitialized]
  137 |         int Max = -INF, pos_y;
      |                         ^~~~~
#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...