QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106197#6394. Turn on the Lightblzgods#WA 3ms3480kbC++11637b2023-05-16 21:17:112023-05-16 21:17:14

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 21:17:14]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3480kb
  • [2023-05-16 21:17:11]
  • 提交

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;
			if(j-i<=2) mid+=1;
		}
	}

	cout.flush();
	return 0;
 }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3480kb

input:

10
1
0
1
2
2

output:

? 1
? 6
? 3
? 4
? 6
! 6

result:

wrong answer Wrong answer, more than 1 possible light!