QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106126#6394. Turn on the Lightbigdinnerafterac#WA 2ms3416kbC++11540b2023-05-16 18:03:462023-05-16 18:03:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 18:03:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3416kb
  • [2023-05-16 18:03:46]
  • 提交

answer

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

int query(int x) {
	int res;
	cout << "? " << x << endl;
	cout.flush();
	cin >> res;
	return res;
}

int main() {
	int n;
	cin >> n;

	int l = 1, r = n;
	int d1 = query(1);

	while (l < r) {
		int m = (l + r) / 2;
		int d2 = query(m);
		int d = d1 - d2;

		if (d == 0) {
			cout << "! " << m << endl;
			break;
		}

		if (d > 0) {
			r = m - 1;
		} else {
			l = m + 1;
			d1 = d2;
		}
	}

	if (l == r) {
		cout << "! " << l << endl;
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3416kb

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

score: 0
Accepted
time: 2ms
memory: 3296kb

input:

10
1
2
3
3

output:

? 1
? 5
? 8
? 9
! 9

result:

ok Correct position at 9

Test #3:

score: 0
Accepted
time: 2ms
memory: 3304kb

input:

9
1
2
3
3

output:

? 1
? 5
? 7
? 8
! 8

result:

ok Correct position at 8

Test #4:

score: 0
Accepted
time: 1ms
memory: 3356kb

input:

8
1
2
3
3

output:

? 1
? 4
? 6
? 7
! 7

result:

ok Correct position at 7

Test #5:

score: 0
Accepted
time: 2ms
memory: 3240kb

input:

7
1
2
3

output:

? 1
? 4
? 6
! 7

result:

ok Correct position at 7

Test #6:

score: 0
Accepted
time: 0ms
memory: 3360kb

input:

6
1
2
3

output:

? 1
? 3
? 5
! 6

result:

ok Correct position at 6

Test #7:

score: 0
Accepted
time: 2ms
memory: 3300kb

input:

5
1
2
3

output:

? 1
? 3
? 4
! 5

result:

ok Correct position at 5

Test #8:

score: 0
Accepted
time: 0ms
memory: 3392kb

input:

4
1
2
3

output:

? 1
? 2
? 3
! 4

result:

ok Correct position at 4

Test #9:

score: 0
Accepted
time: 0ms
memory: 3364kb

input:

3
1
1

output:

? 1
? 2
! 2

result:

ok Correct position at 2

Test #10:

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

input:

2
1
1

output:

? 1
? 1
! 1

result:

wrong answer Wrong favorite light!