QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882497#9734. Identify ChordHildaHuWA 1ms3584kbC++141.6kb2025-02-05 08:34:312025-02-05 08:34:31

Judging History

This is the latest submission verdict.

  • [2025-02-05 08:34:31]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3584kb
  • [2025-02-05 08:34:31]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int T, n, dis, res;
int query(int x, int y) {
	x = (x - 1) % n + 1, y = (y - 1) % n + 1;
	cout << "? " << x << " " << y << endl;
	int tmp; cin >> tmp;
	return tmp;
}
void ans(int x, int y) {
	cout << "! " << x << " " << y << endl;
	cin >> res;
	if (res == -1) exit(0);
}
int getx(int x, int y) {
	int l = x, r = y, ret = -1;
	if (l > r) r += n;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (query(mid, y) == dis - (mid - x)) ret = mid, l = mid + 1;
		else r = mid - 1;
	}
	return ret;
}
void solve1(int x, int y) {
	int retx = getx(x, y), rety = -1;
	int l = retx, r = y;
	if (l > r) r += n;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (query(x, mid) == dis - (y - mid + n) % n) rety = mid, r = mid - 1;
		else l = mid + 1;
	}
	ans(retx, rety);
}
void solve2(int x, int y) {
	int retx = getx(x, y), rety = -1;
	int l = y, r = x;
	if (l > r) r += n;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (query(x, mid) == dis - (mid - y)) rety = mid, l = mid + 1;
		else r = mid - 1; 
	}
	ans(retx, rety);
}
bool work(int x, int y) {
	dis = query(x, y);
	if (dis == n / 2) return false;
	bool dx = query(x + 1, y) == dis - 1;
	bool dy = query(x, y + 1) == dis - 1;
	if (dx && !dy) solve1(x, y);
	else if (!dx && dy) solve1(y, x);
	else if (dx && dy) solve2(x, y);
	else solve2(y, x);
	return true;
}

int main() {
	cin >> T;
	while (T--) {
		cin >> n;
		int x = 1, y = x + n / 2;
		while (!work(x, y)) {
			if (n & 1) {
				if ((y - x + n) % n == n / 2 + 1) x = x % n + 1;
				else y = y % n + 1;
			} else x = x % n + 1, y = y % n + 1;
		}
	}
	return 0;
}

詳細信息

Test #1:

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

input:

2
6
2
1
2
1
1
2
2
1
4
1
1
1
1
1
1
1
1

output:

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

result:

ok ok (2 test cases)

Test #2:

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

input:

1000
15
5
4
6
2
2
1
5
6
5
1
19
5
4
4
5
4
3
4
5
3
4
1
17
5
4
4
4
4
3
4
5
4
3
4
1
15
6
6
7
4
7
6
4
6
6
-1

output:

? 1 8
? 2 8
? 1 9
? 4 8
? 6 8
? 5 8
? 1 6
? 1 7
? 1 8
! 5 8
? 1 10
? 2 10
? 1 11
? 5 10
? 2 10
? 3 10
? 4 10
? 1 15
? 1 12
? 1 13
! 3 12
? 1 9
? 2 9
? 1 10
? 5 9
? 2 9
? 3 9
? 4 9
? 1 13
? 1 10
? 1 11
? 1 12
! 3 11
? 1 8
? 2 8
? 1 9
? 12 1
? 9 1
? 8 1
? 8 4
? 8 2
? 8 1
! 8 1

result:

wrong answer Wrong answer n=15, actual=1-3, guessed=8-1 (test case 4)