QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#348105#8239. Mysterious TreeFreeuni1#WA 1ms3624kbC++14909b2024-03-09 16:58:282024-03-09 16:58:30

Judging History

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

  • [2024-03-09 16:58:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-03-09 16:58:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
bool ask(int a, int b) {
	cout <<"? "<< a << " " << b << endl;
	int p;
	cin >> p;
	return p;
}
int main() {
	int t;
	cin >> t;
	while (t --) {
		int n;
		cin >> n;
		int a = -1, b = -1;
		for (int i = 1; i <= n; i += 2) {
			int A = i;
			int B = (i % n) + 1;
			if (ask(A, B)) {
				a = A;
				b = B;
				break;
			}
		}
		if (a == -1) {
			cout << "! 1" << endl;
			continue;
		}
		int c = (a % n) + 1;
		if (c == b) {
			c = (c + 1) % n;
		}

		if (ask(a, c)) {
			c = (c % n) + 1;
			if (c == b) {
				c = (c % n) + 1;
			}
			if (ask(a, c)) cout << "! 2" << endl;
			else cout << "! 1" << endl;
		} else {
			if (ask(b, c)) {
				c = (c % n) + 1;
				if (c == b) {
					c = (c % n) + 1;
				}
				if (ask(b, c)) cout << "! 2" << endl;
				else cout << "! 1" << endl;
			} else cout << "! 1" << endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

2
4
1
0
1
0
4
0
1
1
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3624kb

input:

87
13
0
0
0
0
0
1

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 0

result:

wrong answer Integer 0 violates the range [1, 13] (test case 1)