QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883496 | #9734. Identify Chord | lzc0115 | WA | 0ms | 3584kb | C++14 | 1.4kb | 2025-02-05 16:39:11 | 2025-02-05 16:39:14 |
Judging History
answer
#include<iostream>
#include<algorithm>
using namespace std;
int t, n, w;
int Ask(int x, int y){
int ans;
cout << "? " << x + 1 << " " << y + 1 << endl;
cin >> ans;
return ans;
}
void Ans(int x, int y){
int ans;
cout << "! " << x + 1 << " " << y + 1 << endl;
cin >> ans;
if(ans == -1) exit(0);
}
int main(){
cin >> t;
while(t--){
cin >> n;
int x = 0, y = (n + 1) / 2, d = 0, p;
w = Ask(x, y);
while(w == n / 2){
if(!(n & 1)) x++, y++;
else if(y - x == (n + 1) / 2) x++;
else y++;
w = Ask(x, y);
}
int a = Ask((x + 1) % n, y), b = Ask((x + n - 1) % n, y);
d = n / 2 - (w - 1);
if(a >= w && b >= w) p = x;
else if(a < w){
if(y - x - 1 == n / 2) x++, w = a, d = n / 2 - (a - 1);
int l = 1, r = n / 2;
while(l <= r){
int mid = (l + r) >> 1;
if(Ask((x + mid) % n, y) == w - mid) l = mid + 1;
else r = mid - 1;
}
p = (x + l - 1) % n;
} else if(b < w){
if(n - (y - x + 1) == n / 2) x = (x + n - 1) % n, w = b, d = n / 2 - (b - 1);
int l = 1, r = n / 2;
while(l <= r){
int mid = (l + r) >> 1;
if(Ask((x + n - mid) % n, y) == w - mid) l = mid + 1;
else r = mid - 1;
}
p = (x + n - l + 1) % n;
}
if(Ask(p, (p + d) % n) == 1) Ans(p, (p + d) % n);
else Ans(p, (p + n - d) % n);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
2 6 2 1 2 1 1 1 1 4 1 1 1 1 1
output:
? 1 4 ? 2 4 ? 6 4 ? 3 4 ? 2 4 ? 2 4 ! 2 4 ? 1 3 ? 2 3 ? 4 3 ? 1 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3456kb
input:
1000 15 6 5 6 3 3 2 1 1 19 4 3 5 4 3 2 3 -1
output:
? 1 9 ? 2 9 ? 15 9 ? 6 9 ? 4 9 ? 5 9 ? 5 8 ! 5 8 ? 1 11 ? 2 11 ? 19 11 ? 7 11 ? 4 11 ? 3 11 ? 3 10 ! 3 15
result:
wrong answer Wrong answer n=19, actual=3-12, guessed=3-15 (test case 2)