QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599482 | #8939. Permutation | zookeeper | WA | 1ms | 3580kb | C++14 | 1.2kb | 2024-09-29 05:30:44 | 2024-09-29 05:30:44 |
Judging History
answer
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//double PHI = (sqrt(5) - 1)/2;
double PHI = 0.3333;
int solve() {
int N;
cin >> N;
int L = 1, R = N, S = -1;
while (true) {
if (L == R) return L;
if (S == -1) {
cout << "? " << L << ' ' << R << endl;
cin >> S;
}
if (L + 1 == R) {
return S == L ? R : L;
}
if (S <= (L + R)/ 2) {
int M = L + int((R - L) * PHI);
cout << "? " << L << ' ' << M << endl;
int S1;
cin >> S1;
if (S1 == S) {
R = M;
} else {
L = M+1;
S = -1;
}
} else {
int M = R - int((R - L) * PHI);
cout << "? " << M << ' ' << R << endl;
int S1;
cin >> S1;
if (S1 == S) {
L = M;
} else {
R = M-1;
S = -1;
}
}
}
}
int main() {
fastio;
int T;
cin >> T;
for (;T>0;T--) {
int s = solve();
cout << "! " << s << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3580kb
input:
3 5 3 1 3
output:
? 1 5 ? 1 2 ? 3 5 ? 3 3
result:
wrong answer Integer 3 violates the range [4, 5] (test case 1)