QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#366966 | #8239. Mysterious Tree | meronri | TL | 1ms | 3736kb | C++14 | 2.2kb | 2024-03-25 15:19:23 | 2024-03-25 15:19:23 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void work()
{
int N;scanf("%d",&N);
int times=(N+1)/2+3;
int ans;
for (int i=1;i*2<=N;i++)
{
int x=i*2-1,y=i*2,z,w;
printf("? %d %d\n",x,y);
fflush(stdout);
scanf("%d",&ans);
if (ans==1)
{
z=x==1?N:x-1;
w=z==1?N:z-1;
printf("? %d %d\n",x,z);
fflush(stdout);
scanf("%d",&ans);
if (ans==1)
{
printf("? %d %d\n",x,w);
fflush(stdout);
scanf("%d",&ans);
if (ans==1)
{
printf("! 2\n");
fflush(stdout);
return;
}
else
{
printf("! 1\n");
fflush(stdout);
return;
}
}
else
{
printf("? %d %d\n",y,z);
fflush(stdout);
scanf("%d",&ans);
if (ans==1)
{
printf("? %d %d\n",y,w);
fflush(stdout);
scanf("%d",&ans);
if (ans==1)
{
printf("! 2\n");
fflush(stdout);
return;
}
else
{
printf("! 1\n");
fflush(stdout);
return;
}
}
else
{
printf("! 1\n");
fflush(stdout);
return;
}
}
}
}
}
int main()
{
int T;scanf("%d",&T);
while (T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3736kb
input:
2 4 1 0 0 4 0 1 1 1
output:
? 1 2 ? 1 4 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 2 ? 3 1 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 1 7 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 10 ? 12 10 ? 12 9 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 13 12 ? 13 11 ! 2 ? 1 2 ? 3 4 ? 5 6