QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378398#8239. Mysterious TreePZhengWA 1ms3512kbC++141.5kb2024-04-06 12:28:502024-04-06 12:28:51

Judging History

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

  • [2024-04-06 12:28:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2024-04-06 12:28:50]
  • 提交

answer

#include <iostream>
#include <set>
#include <vector>

using i64 = long long;
using namespace std;

void solve() {
	int n;
	cin >> n;
	set<int> in[3];
	vector<int> inn(n + 1, 0);
	for(int i = 1; i <= n; i++) {
		in[0].insert(i);
	}
	for(int i = 1; i < n; i += 2) {
		cout << "?" << ' ' << i << ' ' << i + 1 << endl;
		int op;
		cin >> op;
		if(op == 1) {
			inn[i]++;
			inn[i + 1]++;
			in[0].erase(i);
			in[1].insert(i);
			in[0].erase(i + 1);
			in[1].insert(i + 1);
		}
	}
	if(n % 2) {
		cout << "?" << ' ' << 1 << ' ' << n << endl;
		int op;
		cin >> op;
		if(op == 1) {
			inn[1]++;
			in[inn[1] - 1].erase(1);
			in[inn[1]].insert(1);
			in[0].erase(n);
			in[1].insert(n);
		}
	}
	if(in[1].size() >= 4) {
		cout << "!" << ' ' << 1 << endl;
		return;
	}
	if(in[1].empty() && in[2].empty()) {
		cout << "!" << ' ' << 1 << endl;
		return;
	}
	if(in[2].empty()) {
		for(auto x : in[1]) {
			cout << "?" << ' ' << *in[0].begin() << ' ' << x << endl;
			int op;
			cin >> op;
			if(op == 1) {
				in[0].erase(*in[0].begin());
				in[2].insert(x);
				break;
			}	
		} 
	}
	if(in[2].empty()) {
		cout << "!" << ' ' << 1 << endl;
		return;
	}
	cout << "?" << ' ' << *in[0].begin() << ' ' << *in[2].begin() << endl;
	int op;
	cin >> op;
	if(op == 1) {
		cout << "!" << ' ' << 1 << endl;
		return;
	}
	else {
		cout << "!" << ' ' << 2 << endl;
		return;
	}
}

int main() {
	int t = 1;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1
1
4
0
1
1
1

output:

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

result:

wrong answer Wrong prediction (test case 2)