Submission #234979

# Submission time Handle Problem Language Result Execution time Memory
234979 2020-05-26T13:51:17 Z spacewalker Nizovi (COI14_nizovi) C++14
100 / 100
170 ms 480 KB
#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);
		if (i % 2 == 0) {
			reverse(cAStart + 1, injectPoint - 1);
			reverse(cAStart, cAStart + spanLenB);
		} else {
			reverse(cAStart, injectPoint - 1);
			reverse(cAStart, cAStart + spanLenB - 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 256 KB Output is correct
2 Correct 8 ms 256 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 42 ms 384 KB Output is correct
5 Correct 45 ms 256 KB Output is correct
6 Correct 45 ms 376 KB Output is correct
7 Correct 170 ms 480 KB Output is correct
8 Correct 159 ms 376 KB Output is correct
9 Correct 170 ms 372 KB Output is correct
10 Correct 163 ms 384 KB Output is correct