QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106196#6394. Turn on the Lightblzgods#WA 2ms3376kbC++11627b2023-05-16 20:57:212023-05-16 20:57:22

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 20:57:22]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3376kb
  • [2023-05-16 20:57:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,k=0;
bool b[1000010]={false};

int main()
{
	cin>>n;
	cout<<"? 1"<<endl;
	cin>>m;//获取交流的值 
	int i=1,j=n,mid=n/2+1;
	if(m==0) cout<<"! 1"<<endl;
	else
	{
		while(m!=k)
		{
			cout<<"? "<<mid<<endl;//询问中间的结果
			k=m;//保存上一个回答 
			cin>>m;//接受回答
			if(m>k) //mid在左边 
			{
				i=mid;
				
			}
			else if(k>m) // mid在右边 
			{
				j=mid;
			}
			else //mid就是其本身 
			{
				cout<<"! "<<mid<<endl;
				return 0; 
			}
			mid=(i+j)/2+1;
		}
	}
	
	cout.flush();
	return 0;
 }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3376kb

input:

10
1
0
1
1

output:

? 1
? 6
? 4
? 6
! 6

result:

wrong answer Wrong answer, more than 1 possible light!