QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378417#6394. Turn on the Lightinnovation#WA 0ms3552kbC++14675b2024-04-06 12:45:132024-04-06 12:45:13

Judging History

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

  • [2024-04-06 12:45:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-04-06 12:45:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll check(ll x)
{
	ll y;
	cout<<"? "<<x<<endl;
	cin>>y;
	return y;
}
int main()
{
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, L, R, mid, ans;
	cin>>n;
	L = 1;
	R = n;
	ans = 0;
	while(L<=R)
	{
		mid = L+R>>1;
		ll tmp = check(mid);
		if(tmp==ans)
		{
			cout<<"! "<<mid<<endl;
			return 0;
		}
		else 
		{
			ll x;
			cout<<"? "<<R<<endl;
			cin>>x;
			if(x==tmp)
			{
				cout<<"! "<<R<<endl;
				return 0;
			}
			else if(x<tmp)
			{//减少了.  
				L = mid+1;
			}
			else if(x>tmp)
			{
				R = mid-1;
			}
			ans = x;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
1

output:

? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
0
1
1

output:

? 5
? 10
? 8
? 10
! 10

result:

wrong answer Wrong answer, more than 1 possible light!