# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
234955 | spacewalker | Nizovi (COI14_nizovi) | C++14 | 168 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |