Submission #742423

#TimeUsernameProblemLanguageResultExecution timeMemory
742423jamezzzWorm Worries (BOI18_worm)C++17
59 / 100
915 ms5616 KiB
#include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf int n,m,k,q,dx[]={1,0,0,-1,0,0},dy[]={0,1,0,0,-1,0},dz[]={0,0,1,0,0,-1}; map<tuple<int,int,int>,int> memo; mt19937 rng(time(0)); int ask(int a,int b,int c){ if(memo.find({a,b,c})!=memo.end())return memo[{a,b,c}]; pf("? %d %d %d\n",a,b,c); fflush(stdout); int x;sf("%d",&x); return memo[{a,b,c}]=x; } void submit(int a,int b,int c){ pf("! %d %d %d\n",a,b,c); fflush(stdout); exit(0); } int bad(int a,int b,int c){ return a<=0||b<=0||c<=0||a>n||b>m||c>k; } int main(){ sf("%d%d%d%d",&n,&m,&k,&q); int Q=q; tuple<int,int,int,int> ans={0,0,0,0}; for(int i=0;i<Q/2;++i){ int x=rng()%n+1,y=rng()%m+1,z=rng()%k+1; ans=max(ans,{ask(x,y,z),x,y,z}); } auto[cur,x,y,z]=ans; while(q){ bool done=true; for(int i=0;i<6;++i){ int nx=x+dx[i],ny=y+dy[i],nz=z+dz[i]; if(bad(nx,ny,nz))continue; int res=ask(nx,ny,nz); if(res>cur){ cur=res,x=nx,y=ny,z=nz; done=false; break; } } if(done)break; } submit(x,y,z); }

Compilation message (stderr)

worm.cpp: In function 'int ask(int, int, int)':
worm.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  int x;sf("%d",&x);
      |          ^
worm.cpp: In function 'int main()':
worm.cpp:30:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  sf("%d%d%d%d",&n,&m,&k,&q);
      |    ^
#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...