QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371724#6394. Turn on the Lightacansaidong#WA 1ms3848kbC++23687b2024-03-30 15:12:372024-03-30 15:12:38

Judging History

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

  • [2024-03-30 15:12:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3848kb
  • [2024-03-30 15:12:37]
  • 提交

answer

#include <bits/stdc++.h>
#include <sstream>

//#define int long long
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;

using namespace std;

signed main() {
    int n,x,y;
    cin>>n;
    int a=0,aa=0;
    int l=1,r=n;
    while(l<=r) {
    	int x,y;
        printf("? %d\n",l);
        cin>>x;
        if(x==a)
        {
			printf("! %d\n",l);return 0;
		}
		printf("? %d\n",(l+r)/2);
		cin>>y;
		if(y==x)
        {
			printf("! %d\n",(l+r)/2);return 0;
		}
		else if(x<y)
		{
			l=(l+r)/2+1;
		}
		else if(x>y)
		{
			r=(l+r)/2-1;
		}
        a=y;
    }
    printf("! %d",l);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3740kb

input:

10
1
2
3
4
5
5

output:

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

result:

wrong answer Wrong favorite light!