#include <bits/stdc++.h>
using namespace std;
int cmp(int x, int y) {
printf("cmp %d %d\n", x + 1, y + 1);
fflush(stdout);
int ret; scanf("%d", &ret);
return ret;
}
void reverse(int x, int y) {
if (x > y) return;
printf("reverse %d %d\n", x + 1, y + 1);
fflush(stdout);
}
void end() {
printf("end\n");
fflush(stdout);
exit(0);
}
int main() {
int aLen, bLen; scanf("%d %d", &aLen, &bLen);
vector<int> posInB(aLen);
for (int i = 0; i < aLen; ++i) {
int lo = 0, hi = bLen - 1;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (cmp(i, aLen + mid) < 1) hi = mid;
else lo = mid + 1;
}
if (cmp(i, aLen + lo) < 1) posInB[i] = aLen + lo;
else posInB[i] = aLen + bLen;
// fprintf(stderr, "%d should be injected before %d\n", i, posInB[i]);
}
int cAStart = 0, cBStart = aLen;
for (int i = 0; i < aLen; ++i) {
int injectPoint = posInB[i];
int spanLenB = injectPoint - cBStart;
int curALen = aLen - i;
// fprintf(stderr, "[%d len %d][%d len %d](ip %d)\n", cAStart, curALen, cBStart, spanLenB, injectPoint);
reverse(cAStart, injectPoint - 1);
reverse(cAStart, cAStart + spanLenB - 1);
reverse(cAStart + spanLenB, injectPoint - 1);
cAStart += spanLenB + 1; cBStart = cAStart + curALen - 1;
}
end();
return 0;
}
Compilation message
nizovi.cpp: In function 'int cmp(int, int)':
nizovi.cpp:8:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int ret; scanf("%d", &ret);
~~~~~^~~~~~~~~~~~
nizovi.cpp: In function 'int main()':
nizovi.cpp:25:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int aLen, bLen; scanf("%d %d", &aLen, &bLen);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
256 KB |
Output is correct |
3 |
Correct |
7 ms |
384 KB |
Output is correct |
4 |
Correct |
44 ms |
384 KB |
Output is correct |
5 |
Correct |
46 ms |
256 KB |
Output is correct |
6 |
Correct |
45 ms |
384 KB |
Output is correct |
7 |
Correct |
146 ms |
480 KB |
Output is correct |
8 |
Correct |
162 ms |
504 KB |
Output is correct |
9 |
Correct |
168 ms |
376 KB |
Output is correct |
10 |
Incorrect |
163 ms |
376 KB |
Total cost of reverse commands > 3 000 000 |