QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574774 | #6394. Turn on the Light | GammaRays | WA | 1ms | 3716kb | C++23 | 1.2kb | 2024-09-19 00:25:12 | 2024-09-19 00:25:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int tag;
int n;
int L, R, LST;
void solve(int l,int r,int lst)
{
if(tag==1)
{
return;
}
int mid,x,y;
mid=(l+r)>>1;
if (l + 1 < r) {
} else {
L = l;
R = r;
LST = lst;
return;
}
cout<<"? "<<mid<<"\n";
cout.flush();
cin>>x;
if(x==lst)
{
tag=1;
cout<<"! "<<mid;
cout.flush();
return;
}
cout<<"? "<<r<<"\n";
cout.flush();
cin>>y;
if(y==x)
{
tag=1;
cout<<"! "<<r;
cout.flush();
return;
}
// cout<<x<<" "<<y<<endl;
if(x<y)
{
solve(l,max(l,mid-1),y);
}
else
{
solve(min(r-1,mid+1),r-1,y);
}
return;
}
int main()
{
int n;
cin>>n;
tag=0;
solve(1,n,0);
if (tag) return 0;
int res;
// cout << L << ' ' << R << endl;
cout << "? " << L << endl;
cin >> res;
if (res == LST) {
cout<<"! "<< L;
return 0;
}
LST = res;
cout << "? " << L << endl;
cin >> res;
if (res == LST) {
cout<<"! "<< R;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3676kb
input:
3 1 1
output:
? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
10 1 0 1 0 0
output:
? 5 ? 10 ? 7 ? 9 ? 8 ! 8
result:
ok Correct position at 8
Test #3:
score: 0
Accepted
time: 1ms
memory: 3672kb
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: 3712kb
input:
8 1 0 1 1
output:
? 4 ? 8 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
7 1 2 3 4 4
output:
? 4 ? 7 ? 2 ? 3 ? 1 ! 1
result:
ok Correct position at 1
Test #6:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
6 1 0 1 1
output:
? 3 ? 6 ? 4 ? 4 ! 5
result:
ok Correct position at 5
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 1 2 2
output:
? 3 ? 5 ? 1 ! 1
result:
ok Correct position at 1
Test #8:
score: 0
Accepted
time: 0ms
memory: 3592kb
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: 0ms
memory: 3652kb
input:
2 1 1
output:
? 1 ? 1 ! 2
result:
ok Correct position at 2
Test #11:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 0
output:
? 1 ! 1
result:
ok Correct position at 1
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
input:
1000000 1 0 1 2 3 4 3 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 25
output:
? 500000 ? 1000000 ? 750000 ? 999999 ? 625000 ? 749999 ? 562500 ? 624999 ? 531250 ? 562499 ? 546874 ? 562498 ? 554686 ? 562497 ? 550780 ? 554685 ? 548827 ? 550779 ? 547850 ? 548826 ? 547362 ? 547849 ? 547118 ? 547361 ? 546996 ? 547117 ? 546935 ? 546995 ? 546904 ? 546934 ? 546889 ? 546903 ? 546881 ? ...
result:
wrong answer Wrong answer, more than 1 possible light!