QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745545#8239. Mysterious TreezaqmjuWA 1ms3632kbC++231.1kb2024-11-14 10:30:572024-11-14 10:30:58

Judging History

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

  • [2024-11-14 10:30:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2024-11-14 10:30:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'

int ask(int u, int v) {
	cout << "? " << u << " " << v << "\n";
	fflush(stdout);
	int g;
	cin >> g;
	return g;
}
void ans(int u) {
	cout << "! " << u << "\n";
	fflush(stdout);
}

void solve() {
	bool flag = 1;
	int x = 0, y = 0;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i += 2) {
		int a = i;
		int b = i + 1;
		if(i == n)b = i - 1;
		int t = ask(a, b);
		if(t == 1) {
			flag = false;
			x = a, y = b;
			break;
		}
	}
	if(flag) {
		ans(2);
	}
	else {
		int a = 0, b = 0;
		for(int i = 1; i <= n; i++) {
			if(i != x && i != y) {
				if(!a) a = i;
				else if(!b) b = i;
				else break;
			}
		}
		int t = ask(x, a);
		if(t == 1) {
			t = ask(x, b);
			if(t == 1)ans(1);
			else ans(2);
		}
		else {
			t = ask(y, a);
			if(t == 1) {
				t = ask(y, b);
				if(t)ans(1);
				else ans(2);
			}
			else ans(2);
		}
	}
}
#undef int
int main() {
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	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: 3632kb

input:

2
4
1
0
1
0

output:

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

result:

wrong answer Wrong prediction (test case 1)