QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748350#8239. Mysterious TreeCSQ#WA 1ms3576kbC++171023b2024-11-14 20:08:022024-11-14 20:08:05

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 20:08:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3576kb
  • [2024-11-14 20:08:02]
  • 提交

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() {
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		bool ok = 0;
		int ans = 1;
		for(int i=1;i+1<=n;i+=2){
			if(!ask(i,i+1))continue;
			ok = 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{
				if(ask(i+1,a[0])){
					if(ask(i+1,a[1]))ans = 2; //star
				}
			}
		}
		if(!ok && n&1){
			ans = 1;
			if(ask(n-1,n)){
				if(ask(n-1,1)){
					if(ask(n-1,2))ans = 2; //star 
				}else{
					if(ask(n,1)){
						if(ask(n,2))ans = 2; //star
					}
				}
			}
		}
		cout<<"! "<<ans<<endl;
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3576kb

input:

2
4
1
0
1
0
1

output:

? 1 2
? 1 3
? 2 3
? 2 4
? 3 4
? 3 1

result:

wrong answer Too many queries , n = 4 , now_q 6 (test case 1)