제출 #266459

#제출 시각아이디문제언어결과실행 시간메모리
266459TadijaSebezWorm Worries (BOI18_worm)C++11
78 / 100
839 ms5648 KiB
#include <bits/stdc++.h> using namespace std; map<array<int,3>,int> was; int n,m,k,q; int Ask(int i,int j,int k){ if(was.count({i,j,k}))return was[{i,j,k}]; if(i<1||j<1||k<1||i>n||j>m||k>::k)return 0; printf("? %i %i %i\n",i,j,k); fflush(stdout); int b;scanf("%i",&b); was[{i,j,k}]=b; return b; } void Ans(int i,int j,int k){ printf("! %i %i %i\n",i,j,k); fflush(stdout); exit(0); } bool Check(int i,int j,int k){ int now=Ask(i,j,k); for(int a=-1;a<=1;a+=2) if(now<max({Ask(i+a,j,k),Ask(i,j+a,k),Ask(i,j,k+a)})) return 0; Ans(i,j,k); return 1; } mt19937 rng(time(0)); int main(){ scanf("%i %i %i %i",&n,&m,&k,&q); if(m==1&&k==1){ int top=n,bot=1,mid,las=0; while(top>bot){ mid=top+bot>>1; if(las&&top-bot>1){ if(las>mid&&Ask(mid,1,1)<Ask(las,1,1)){bot=mid;continue;} if(las<mid&&Ask(mid,1,1)<Ask(las,1,1)){top=mid;continue;} } if(Ask(mid,1,1)<Ask(mid+1,1,1))bot=mid+1,las=mid+1; else top=mid,las=mid; } Ans(bot,1,1); }else if(k==1){ int X1=1,X2=n,Y1=1,Y2=m,Xm,Ym,last=0; pair<int,int> pre; while(X1<=X2&&Y1<=Y2){ Xm=X1+X2>>1; int mx=0,pos=0; for(int i=Y1;i<=Y2;i++){ int now=Ask(Xm,i,1); if(now>mx)mx=now,pos=i; } if(mx<last){ if(Xm-1>=pre.first)X2=Xm-1; else X1=Xm+1; }else{ if(Ask(Xm-1,pos,1)>mx){ X2=Xm-1; pre={Xm-1,pos}; }else if(Ask(Xm+1,pos,1)>mx){ X1=Xm+1; pre={Xm+1,pos}; }else Ans(Xm,pos,1); last=mx; } Ym=Y1+Y2>>1; mx=0,pos=0; for(int i=X1;i<=X2;i++){ int now=Ask(i,Ym,1); if(now>mx)mx=now,pos=i; } if(mx<last){ if(Ym-1>=pre.second)Y2=Ym-1; else Y1=Ym+1; }else{ if(Ask(pos,Ym-1,1)>mx){ Y2=Ym-1; pre={pos,Ym-1}; }else if(Ask(pos,Ym+1,1)>mx){ Y1=Ym+1; pre={pos,Ym+1}; }else Ans(pos,Ym,1); last=mx; } } }else{ int X,Y,Z,mx=0; for(int i=1;i<=q/2;i++){ int x=rng()%n+1; int y=rng()%m+1; int z=rng()%k+1; if(Ask(x,y,z)>mx){ mx=Ask(x,y,z); X=x; Y=y; Z=z; } } while(!Check(X,Y,Z)){ if(Ask(X+1,Y,Z)>Ask(X,Y,Z))X++; else if(Ask(X-1,Y,Z)>Ask(X,Y,Z))X--; else if(Ask(X,Y+1,Z)>Ask(X,Y,Z))Y++; else if(Ask(X,Y-1,Z)>Ask(X,Y,Z))Y--; else if(Ask(X,Y,Z+1)>Ask(X,Y,Z))Z++; else if(Ask(X,Y,Z-1)>Ask(X,Y,Z))Z--; } } return 0; }

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

worm.cpp: In function 'int main()':
worm.cpp:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |    mid=top+bot>>1;
      |        ~~~^~~~
worm.cpp:46:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |    Xm=X1+X2>>1;
      |       ~~^~~
worm.cpp:65:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |    Ym=Y1+Y2>>1;
      |       ~~^~~
worm.cpp: In function 'int Ask(int, int, int)':
worm.cpp:10:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |  int b;scanf("%i",&b);
      |        ~~~~~^~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%i %i %i %i",&n,&m,&k,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
worm.cpp:104:28: warning: 'Z' may be used uninitialized in this function [-Wmaybe-uninitialized]
  104 |    else if(Ask(X,Y,Z-1)>Ask(X,Y,Z))Z--;
      |                         ~~~^~~~~~~
worm.cpp:104:28: warning: 'Y' may be used uninitialized in this function [-Wmaybe-uninitialized]
worm.cpp:104:28: warning: 'X' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...