QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356113 | #8239. Mysterious Tree | ucup-team2681# | TL | 1ms | 3824kb | C++23 | 1.2kb | 2024-03-17 15:40:51 | 2024-03-17 15:40:52 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int,int>
#define lowbit(x) (x&-x)
using namespace std;
int n;
bool qry(int x,int y){
printf("? %d %d",x,y);cout<<endl;
int p;
scanf("%d",&p);
return p;
}
void solve(int x,int y){
for(int i=1;i<=n;i++){
if(i!=x&&i!=y){
if(qry(i,x)){
for(int j=1;j<=n;j++){
if(j==i||j==x||j==y)continue;
if(qry(j,x)){
printf("! 2");
cout<<endl;
return;
}
else{
printf("! 1");
cout<<endl;
return;
}
}
}
else{
break;
}
}
}
swap(x,y);
for(int i=1;i<=n;i++){
if(i!=x&&i!=y){
if(qry(i,x)){
for(int j=1;j<=n;j++){
if(j==i||j==x||j==y)continue;
if(qry(j,x)){
printf("! 2");
cout<<endl;
return;
}
else{
printf("! 1");
cout<<endl;
return;
}
}
}
else{
break;
}
}
}
printf("! 1");
cout<<endl;
}
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;i+=2){
int tmp=i;
if(i==n)tmp--;
if(qry(tmp,tmp+1)){
solve(tmp,tmp+1);
return;
}
}
}
int main(){
int t=1;
scanf("%d",&t);
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3824kb
input:
2 4 1 0 1 0 4 0 1 1 1
output:
? 1 2 ? 3 1 ? 3 2 ? 4 2 ! 1 ? 1 2 ? 3 4 ? 1 3 ? 2 3 ! 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 1 0 1 1 15 0 0 0 1 0 0 19 0 0 0 0 0 1 1 1 20 0 0 0 0 0 0 0 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 11 ? 1 12 ? 2 12 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 1 13 ? 2 13 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 6 7 ? 1 6 ? 1 7 ? 2 7 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 1 7 ? 1 8 ! 1 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 11 ? 2 11 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 ...