QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136500#6394. Turn on the Lightammardab3an#WA 2ms3600kbC++17832b2023-08-08 21:45:262023-08-08 21:45:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 21:45:30]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3600kb
  • [2023-08-08 21:45:26]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long


using namespace std;

const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;

int ask(int x) {
	cout << "? " << x << endl;
	int y; cin >> y;
	return y;
}

int solve() {
	int n; cin >> n;
	int l = 1, r = n;
	int res = 0;
	int cur = 0;
	while (l <= r) {
		int mid = l + r >> 1;
		int y = ask(l);
		if (y == cur) {
			res = l;
			break;
		}
		int y1 = ask(mid);
		if (y1 == y) {
			res = mid;
			break;
		}
		if (y1 == cur) {
			r = mid - 1;
			l++;
		}
		else {
			l = mid + 1;
		}
		cur = y1;
	}
	cout << "! " << res << endl;
	return 0;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	int i = 1;
	while (t--) {
		//cout << "case " << i << ": ";
		solve();
	}
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3600kb

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3532kb

input:

10
1
2
3
4
5
5

output:

? 1
? 5
? 6
? 8
? 9
? 9
! 9

result:

wrong answer Wrong favorite light!