QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138371 | #6394. Turn on the Light | Schi2oid | WA | 2ms | 5672kb | C++14 | 941b | 2023-08-11 16:43:45 | 2023-08-11 16:44:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int ask(int x){
int ret;
cout<<"? "<<x<<endl;
cin>>ret;
return ret;
}
int id[2][2000005];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) id[0][i]=i;
bool op=0;
int bef=0;
while(n>=4){
int p1=n/4,p2=n-n/4;
int x=ask(id[op][p1]);
if(x==bef){
cout<<"! p1";
return 0;
}
int y=ask(id[op][p2]);
if(y==x){
cout<<"! p2";
return 0;
}
int delta=y-bef;
op^=1;
if(delta==0){
n=p2-p1;
int cnt=0;
for(int i=p1+1;i<p2;i++){
id[op][++cnt]=id[op^1][i];
}
}
else{
n=n-p2+p1-1;
int cnt=0;
for(int i=1;i<p1;i++){
id[op][++cnt]=id[op^1][i];
}
for(int i=p2+1;i<=n;i++){
id[op][++cnt]=id[op^1][i];
}
}
bef=y;
}
for(int i=1;i<=n;i++){
int x=ask(id[op][i]);
if(x==bef){
cout<<"! "<<id[op][i];
return 0;
}
bef=x;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 2ms
memory: 5520kb
input:
10 1 0 1 0 1 0 0
output:
? 2 ? 8 ? 3 ? 7 ? 4 ? 6 ? 5 ! 5
result:
ok Correct position at 5
Test #3:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
9 1 0 1 0 1 1
output:
? 2 ? 7 ? 3 ? 6 ? 4 ? 5 ! 5
result:
ok Correct position at 5
Test #4:
score: 0
Accepted
time: 2ms
memory: 5428kb
input:
8 1 0 1 0 0
output:
? 2 ? 6 ? 3 ? 5 ? 4 ! 4
result:
ok Correct position at 4
Test #5:
score: 0
Accepted
time: 2ms
memory: 5496kb
input:
7 1 0 1 0 1 1
output:
? 1 ? 6 ? 2 ? 5 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #6:
score: 0
Accepted
time: 0ms
memory: 5564kb
input:
6 1 0 1 0 0
output:
? 1 ? 5 ? 2 ? 4 ? 3 ! 3
result:
ok Correct position at 3
Test #7:
score: 0
Accepted
time: 1ms
memory: 5524kb
input:
5 1 0 1 1
output:
? 1 ? 4 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3400kb
input:
4 1 1
output:
? 1 ? 3 ! p2
result:
wrong answer format Expected integer, but "p2" found