QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#460641 | #8239. Mysterious Tree | CRN2010 | TL | 1ms | 3656kb | C++20 | 2.2kb | 2024-07-01 23:29:54 | 2024-07-01 23:29:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std ;
void solve() {
int n , op ;
cin >> n ;
for(int i = 2 ; i <= n ; i += 2)
{
cout << "? " << i << ' ' << i - 1 << endl ;
cin >> op ;
if (op)
{
if ( i == n ) {
cout << "? " << 1 << ' ' << i << endl ;
cin >> op ;
if ( op ) {
cout << "? " << 2 << ' ' << i << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
} else {
cout << "? " << 1 << ' ' << i - 1 << endl ;
cin >> op ;
if ( op ) {
cout << "? " << 2 << ' ' << i - 1 << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
} else {
return cout << "! 1" << endl , void();
}
}
} else {
cout << "? " << i << ' ' << n << endl ;
cin >> op ;
if ( op ) {
if ( i == n - 1 ) {
cout << "? " << 1 << ' ' << i << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
} else {
cout << "? " << i << ' ' << n - 1 << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
}
} else {
cout << "? " << i - 1 << ' ' << n << endl ;
cin >> op ;
if ( op ) {
if ( i == n - 1 ) {
cout << "? " << 1 << ' ' << i - 1 << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
} else {
cout << "? " << i - 1 << ' ' << n - 1 << endl ;
cin >> op ;
if ( op ) {
return cout << "! 2" << endl , void() ;
} else {
return cout << "! 1" << endl , void() ;
}
}
} else {
return cout << "! 1" << endl , void() ;
}
}
}
}
}
}
int main()
{
int t ;
cin >> t ;
while (t--)
{
solve() ;
}
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
2 4 1 0 0 4 0 1 0 1 1
output:
? 2 1 ? 2 4 ? 1 4 ! 1 ? 2 1 ? 4 3 ? 1 4 ? 1 3 ? 2 3 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
87 13 0 0 0 0 0 1 1 1 15 0 0 0 0 0 0 1 0 1 1 7 0 0 0
output:
? 2 1 ? 4 3 ? 6 5 ? 8 7 ? 10 9 ? 12 11 ? 12 13 ? 1 12 ! 2 ? 2 1 ? 4 3 ? 6 5 ? 8 7 ? 10 9 ? 12 11 ? 14 13 ? 14 15 ? 13 15 ? 1 13 ! 2 ? 2 1 ? 4 3 ? 6 5