QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748316 | #8239. Mysterious Tree | CSQ# | RE | 0ms | 0kb | C++17 | 1.2kb | 2024-11-14 20:01:03 | 2024-11-14 20:01:04 |
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x); (int) (x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
int ask(int v,int u){
cout<<"? "<<v<<" "<<u<<endl;
int x;
cin>>x;
return x;
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool ok = 0;
int ans = 0;
for(int i=1;i+1<=n;i+=2){
if(!ask(i,i+1))continue;
if(ask(i,i+1)){
vector<int>a;
for(int j=1;j<=n;j++){
if(j != i && j!= i+1)a.push_back(j);
}
ans = 1;
if(ask(i,a[0])){
if(ask(i,a[1]))ans = 2; //star
else ans = 1;
}else{
if(ask(i+1,a[0])){
if(ask(i+1,a[1]))ans = 2; //star
else ans = 1;
}else ans = 1;
}
}
}
if(!ans && n&1){
if(!ask(n-1,n))ans = 1;
else{
if(ask(n-1,1)){
if(ask(n-1,2))ans = 2; //star
else ans = 1;
}else{
if(ask(n,1)){
if(ask(n,2))ans = 2; //star
else ans = 1;
}else ans = 1;
}
}
}else ans = 1;
cout<<"! "<<ans<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 4 1 1 0 1 0
output:
? 1 2 ? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4