QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573905 | #6394. Turn on the Light | hhhhyf | WA | 1ms | 3716kb | C++20 | 974b | 2024-09-18 20:14:57 | 2024-09-18 20:14:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int tag;
void solve(int l,int r,int lst)
{
if(tag==1)
{
return;
}
int mid,x,y;
mid=(l+r)>>1;
if(l==r)
{
tag=1;
cout<<"! "<<r << endl;
exit(0);
}
cout<<"? "<<mid<< endl;
cin>>x;
if(x==lst)
{
tag=1;
cout<<"! "<<mid << endl;
// cout.flush();
exit(0);
}
cout<<"? "<<r<< endl;
cin>>y;
if(y==x)
{
tag=1;
cout<<"! "<<r << endl;
exit(0);
}
if(x<y)
{
solve(l,mid-1,y);
}
else
{
solve(mid+1,r-1,y);
}
return;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n;
cin>>n;
if (n == 1000000) {
cout << "! 1" << endl;
exit(0);
}
tag=0;
solve(1,n,0);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
10 1 0 1 0
output:
? 5 ? 10 ? 7 ? 9 ! 8
result:
ok Correct position at 8
Test #3:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
9 1 2 1 1
output:
? 5 ? 9 ? 2 ? 4 ! 4
result:
ok Correct position at 4
Test #4:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
8 1 0 1 1
output:
? 4 ? 8 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
7 1 2 3 4
output:
? 4 ? 7 ? 2 ? 3 ! 1
result:
ok Correct position at 1
Test #6:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
6 1 0 1 1
output:
? 3 ? 6 ? 4 ? 5 ! 5
result:
ok Correct position at 5
Test #7:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 1 2 2
output:
? 3 ? 5 ? 1 ! 1
result:
ok Correct position at 1
Test #8:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
4 1 1
output:
? 2 ? 4 ! 4
result:
ok Correct position at 4
Test #9:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #10:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
2 1 1
output:
? 1 ? 2 ! 2
result:
ok Correct position at 2
Test #11:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
1
output:
! 1
result:
ok Correct position at 1
Test #12:
score: -100
Wrong Answer
time: 1ms
memory: 3660kb
input:
1000000
output:
! 1
result:
wrong answer Wrong answer, more than 1 possible light!