#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 1e3 + 5;
int a, b;
int sol[MAXN];
int cmp(int x, int y){
cout << "cmp" _ x _ y << endl;
fflush(stdout);
int ret; cin >> ret;
return ret;
}
void rev(int x, int y){
if(x >= y) return;
cout << "reverse" _ x _ y << endl;
fflush(stdout);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> a >> b;
REP(i, a){
int lo = a, hi = a + b;
while(lo < hi){
int mid = (lo + hi + 1) >> 1;
int ans = cmp(i + 1, mid);
if(ans <= 0)
hi = mid - 1;
else
lo = mid;
}
sol[i] = lo;
}
int start = 1, len = a + 1;
REP(i, a){
len --;
if(i && sol[i] == sol[i - 1]) { start ++; continue; }
if(sol[i] == a) { start ++; continue; }
rev(start, sol[i]);
rev(sol[i] - len + 1, sol[i]);
rev(start, sol[i] - len);
start = sol[i] - len + 2;
}
cout << "end";
fflush(stdout);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
43 ms |
548 KB |
Output is correct |
5 |
Correct |
39 ms |
548 KB |
Output is correct |
6 |
Correct |
41 ms |
548 KB |
Output is correct |
7 |
Correct |
153 ms |
556 KB |
Output is correct |
8 |
Correct |
173 ms |
556 KB |
Output is correct |
9 |
Correct |
152 ms |
692 KB |
Output is correct |
10 |
Correct |
196 ms |
692 KB |
Output is correct |