#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int a,b;
int mjesto[MAXN];
int bs (int x, int lo, int hi) {
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
cout << "cmp " << x << ' ' << mid + a << "\n";
cout.flush();
int c;
cin >> c;
if (c == -1) hi = mid - 1;
else lo = mid;
}
return lo;
}
int main () {
// ios_base::sync_with_stdio (false);
// cin.tie (0);
cin >> a >> b;
for (int i = 1; i <= a; i++) mjesto[i] = bs (i, mjesto[i - 1], b);
int lo = 1, hi;
for (int i = 1; i <= a; i++) {
hi = mjesto[i] + a;
if (hi - lo == a - i || lo >= hi) {
lo++;
continue;
}
cout << "reverse " << lo << ' ' << hi << "\n";
cout.flush ();
if ((hi - lo) - (a - i) > 1) {
cout << "reverse " << lo << ' ' << hi - a + i - 1 << "\n";
cout.flush ();
}
if (i < a) {
cout << "reverse " << hi - a + i << ' ' << hi << "\n";
cout.flush ();
}
lo = max (hi - a + i + 1, lo + 1);
}
cout << "end";
cout.flush ();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
15 ms |
284 KB |
Output is correct |
5 |
Correct |
26 ms |
288 KB |
Output is correct |
6 |
Correct |
18 ms |
208 KB |
Output is correct |
7 |
Correct |
133 ms |
292 KB |
Output is correct |
8 |
Correct |
154 ms |
332 KB |
Output is correct |
9 |
Correct |
182 ms |
296 KB |
Output is correct |
10 |
Incorrect |
202 ms |
292 KB |
Total cost of reverse commands > 3 000 000 |