QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748316#8239. Mysterious TreeCSQ#RE 0ms0kbC++171.2kb2024-11-14 20:01:032024-11-14 20:01:04

Judging History

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

  • [2024-11-14 20:01:04]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-14 20:01:03]
  • 提交

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;
	}
}

詳細信息

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

result: