This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
void 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;
Ans(i,j,k);
}
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,las=mid;continue;}
if(las<mid&&Ask(mid,1,1)<Ask(las,1,1)){top=mid,las=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){
/*mt19937 rng(time(0));
for(int i=1;i<=100;i++){
int x=rng()%n+1;
int y=rng()%m+1;
for(int j=1;j<=10;j++){
int now=Ask(x,y,1);
int mx=0;
pair<int,int> nxt;
if(Ask(x+1,y,1)>mx)mx=Ask(x+1,y,1),nxt={x+1,y};
if(Ask(x-1,y,1)>mx)mx=Ask(x-1,y,1),nxt={x-1,y};
if(Ask(x,y+1,1)>mx)mx=Ask(x,y+1,1),nxt={x,y+1};
if(Ask(x,y-1,1)>mx)mx=Ask(x,y-1,1),nxt={x,y-1};
if(mx<=now)Ans(x,y,1);
tie(x,y)=nxt;
}
}
Ans(1,1,1);*/
int X1=1,X2=n,Y1=1,Y2=n,Xm=X1+X2>>1,Ym;
while(X1<X2&&Y1<Y2){
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(min(Ask(Xm-1,pos,1),Ask(Xm+1,pos,1))>mx){
if(Xm-X1<X2-Xm)X2=Xm-1;
else X1=Xm+1;
}else if(Ask(Xm-1,pos,1)>mx){
X2=Xm-1;
}else if(Ask(Xm+1,pos,1)>mx){
X1=Xm+1;
}else Ans(Xm,pos,1);
Ym=pos;
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(min(Ask(pos,Ym-1,1),Ask(pos,Ym+1,1))>mx){
if(Ym-Y1<Y2-Ym)Y2=Ym-1;
else Y1=Ym+1;
}else if(Ask(pos,Ym-1,1)>mx){
Y2=Ym-1;
}else if(Ask(pos,Ym+1,1)>mx){
Y1=Ym+1;
}else Ans(pos,Ym,1);
Xm=pos;
}
for(int i=X1;i<=X2;i++){
for(int j=Y1;j<=Y2;j++){
Check(i,j,1);
}
}
}else{
}
return 0;
}
Compilation message (stderr)
worm.cpp: In function 'int main()':
worm.cpp:31:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | mid=top+bot>>1;
| ~~~^~~~
worm.cpp:58:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int X1=1,X2=n,Y1=1,Y2=n,Xm=X1+X2>>1,Ym;
| ~~^~~
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:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
27 | scanf("%i %i %i %i",&n,&m,&k,&q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |