QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883090 | #9734. Identify Chord | Chendaqian | WA | 1ms | 3840kb | C++14 | 2.0kb | 2025-02-05 14:40:49 | 2025-02-05 14:40:52 |
Judging History
answer
/*
code.cpp
Standard IO
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define db double
using namespace std;
const db eps=1e-6;
const int inf=0x3f3f3f3f;
const ll lnf=(ll)1e18+10;
ll read() {
ll o=0,w=1;char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9') {o=o*10+c-'0';c=getchar();}
return o*w;
}
namespace dada {
int n;
int dis(int x,int y) {
return min((x-y+n)%n,(y-x+n)%n);
}
int ask(int x,int y) {
printf("? %d %d\n",x,y);
fflush(stdout);
return read();
}
int pre(int x,int k) {
return (x-1-k+n)%n+1;
}
int suf(int x,int k) {
return (x-1+k)%n+1;
}
int Main() {
n=read();
int sx=0,sy=0,d=0;
bool fd=0;
for(int i:{1,n,2}) {
for(int j=n/2;j<=(n+1)/2;j++) {
sx=i,sy=suf(i,j);
d=ask(sx,sy);
if(d!=dis(sx,sy)) {
fd=1;
break;
}
}
if(fd) break;
}
if(sx>sy) swap(sx,sy);
if(d==1) {
printf("! %d %d\n",sx,sy);
fflush(stdout);
return read()!=1;
}
// cerr<<d<<'\n';
d=dis(sx,sy)-d;
// cerr<<sx<<' '<<sy<<' '<<d<<'\n';
int d1=ask(pre(sx,1),sy);
int d2=ask(suf(sx,1),sy);
int rt=0;
if(d1==d2) rt=sx;
else if(d1<d2) {
// cerr<<"toL\n";
int l=1,r=(sx-sy+n)%n,res=0;
while(l<=r) {
int mid=(l+r)/2,x=pre(sx,mid);
if(dis(x,sy)==ask(x,sy)+d) res=mid,l=mid+1;
else r=mid-1;
}
rt=pre(sx,res);
} else {
// cerr<<"toR\n";
int l=1,r=(sy-sx+n)%n,res=0;
while(l<=r) {
int mid=(l+r)/2,x=suf(sx,mid);
if(dis(x,sy)==ask(x,sy)+d) res=mid,l=mid+1;
else r=mid-1;
}
rt=suf(sx,res);
}
// cerr<<rt<<'\n';
printf("! %d %d\n",rt,(ask(rt,pre(rt,d+1))==1?pre(rt,d+1):suf(rt,d+1)));
fflush(stdout);
return read()!=1;
}
}
int main() {
int T=read();
while(T--) {
if(dada::Main()) return 0;
}
return 0;
}
/*
cd QOJ9734
g++ code.cpp -o code -std=c++14 -Wall -O2 -static -lm
time ./code
cp 1.in .in
diff .out 1.ans -w | head -n 10
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
2 6 2 2 1 1 1 2 1 4 1 1
output:
? 1 4 ? 6 4 ? 2 4 ? 3 4 ? 2 4 ? 2 6 ! 2 4 ? 1 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
1000 15 5 6 4 1 1 2 3 1 19 5 6 4 4 3 4 5 -1
output:
? 1 8 ? 15 8 ? 2 8 ? 5 8 ? 7 8 ? 6 8 ? 5 2 ! 5 8 ? 1 10 ? 19 10 ? 2 10 ? 6 10 ? 3 10 ? 4 10 ? 3 17 ! 3 8
result:
wrong answer Wrong answer n=19, actual=3-12, guessed=3-8 (test case 2)