#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
bool cmp(int a, int b){
cout << "cmp " << a << ' ' << b << endl;
int x;
cin >> x;
return x <= 0;
}
void rev(int l, int r){
if(l == r) return;
cout << "reverse " << l << ' ' << r << endl;
}
int A, B;
void solve(int pos, int fall){
//cout << "solving: " << pos << ' ' << fall << '\n';
if(pos >= A + B || fall > A + B || pos >= fall) return;
if(cmp(pos, fall)){
int l = pos + 1, r = fall - 1;
while(r > l){
int m = (l + r) / 2;
if(!cmp(m, fall)) r = m;
else l = m + 1;
}
if(l == fall - 1 && cmp(l, fall)) return;
pos = l;
}
//cout << "adjusted to: " << pos << ' ' << fall << '\n';
if(pos >= A + B || fall > A + B || pos >= fall) return;
int l = fall, r = A + B;
while(r > l){
int m = (l + r + 1) / 2;
if(cmp(m, pos)) l = m;
else r = m - 1;
}
rev(pos, l);
rev(pos, pos + l - fall);
rev(pos + l - fall + 1, l);
solve(pos + l - fall + 1, l + 1);
}
int main()
{
cin >> A >> B;
solve(1, A + 1);
cout << "end" << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
43 ms |
208 KB |
Output is correct |
5 |
Correct |
39 ms |
208 KB |
Output is correct |
6 |
Correct |
28 ms |
208 KB |
Output is correct |
7 |
Correct |
258 ms |
208 KB |
Output is correct |
8 |
Correct |
301 ms |
208 KB |
Output is correct |
9 |
Correct |
330 ms |
208 KB |
Output is correct |
10 |
Correct |
201 ms |
292 KB |
Output is correct |