Submission #280213

# Submission time Handle Problem Language Result Execution time Memory
280213 2020-08-22T14:59:46 Z spdskatr Colors (BOI20_colors) C++14
0 / 100
1 ms 256 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cassert>
#include <vector>
#define K 32

using namespace std;

int N;
int seen[1005];
vector<int> qu;
int last = 6969, actual;
int query(int x) {
#ifdef DEBUG
	//printf("query(%d)\n", x);
	int r = abs(x - last) >= actual;
	last = x;
	return r;
#else
	printf("? %d\n", x);
	fflush(stdout);
	int res;
	scanf("%d", &res);
	last = x;
	return res;
#endif
}

void answer(int ans) {
	printf("= %d\n", ans);
	fflush(stdout);
	exit(0);
}

int main() {
	scanf("%d", &N);
#ifdef DEBUG
	scanf("%d", &actual);
#endif
	assert(N <= 1000);
	qu.push_back(0);
	for (int i = 1; i * K < N; i++) {
		if (qu.size() <= 1 || qu[qu.size()-1] < qu[qu.size()-2]) {
			qu.push_back(qu.back() + i * K);
		} else {
			qu.push_back(qu.back() - i * K);
		}
	}
	// Stick to left
	int diff = 1 - qu.back();
	if (qu.back() > 0) {
		// Last move was forward, stick to right
		diff = N - qu.back();
	}
	for (int i = 0; i < qu.size(); i++) qu[i] += diff;
	for (int i = 0; i < qu.size(); i++) {
		int res = query(qu[i]);
		if (i > 0 && res) {
			int low = 0;
			int cur = qu[i];
			if (i >= 2) low = abs(qu[i-1] - qu[i-2]);
			for (int j = abs(qu[i] - qu[i-1]) - 1; j > low; j--) {
				if (cur > qu[0]) {
					cur -= j;
				} else {
					cur += j;
				}
				if (!query(cur)) {
					answer(j+1);
				}
			}
			answer(low+1);
		}
	}
	// Should either be at N or 1
	{
		int cur = qu.back();
		int par = cur <= qu[0];
		for (int j = N-1; j > ((N-1) / K) * K; j--) {
			if (par) {
				cur += j;
			} else {
				cur -= j;
			}
			par = !par;
			if (!query(cur)) {
				answer(j+1);
			}
		}
		answer(((N-1) / K) * K + 1);
	}
}

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i = 0; i < qu.size(); i++) qu[i] += diff;
      |                  ~~^~~~~~~~~~~
Colors.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for (int i = 0; i < qu.size(); i++) {
      |                  ~~^~~~~~~~~~~
Colors.cpp: In function 'int query(int)':
Colors.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  scanf("%d", &res);
      |  ~~~~~^~~~~~~~~~~~
Colors.cpp: In function 'int main()':
Colors.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (5 queries)
2 Correct 0 ms 256 KB OK (7 queries)
3 Correct 0 ms 256 KB OK (10 queries)
4 Correct 1 ms 252 KB OK (26 queries)
5 Correct 0 ms 256 KB OK (13 queries)
6 Correct 0 ms 256 KB OK (3 queries)
7 Correct 1 ms 256 KB OK (18 queries)
8 Correct 0 ms 256 KB OK (8 queries)
9 Correct 1 ms 256 KB OK (10 queries)
10 Correct 0 ms 256 KB OK (11 queries)
11 Correct 0 ms 256 KB OK (4 queries)
12 Correct 0 ms 256 KB OK (5 queries)
13 Correct 0 ms 256 KB OK (12 queries)
14 Incorrect 0 ms 256 KB Integer parameter [name=k] equals to -17, violates the range [1, 44]
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (5 queries)
2 Correct 0 ms 256 KB OK (7 queries)
3 Correct 0 ms 256 KB OK (10 queries)
4 Correct 1 ms 252 KB OK (26 queries)
5 Correct 0 ms 256 KB OK (13 queries)
6 Correct 0 ms 256 KB OK (3 queries)
7 Correct 1 ms 256 KB OK (18 queries)
8 Correct 0 ms 256 KB OK (8 queries)
9 Correct 1 ms 256 KB OK (10 queries)
10 Correct 0 ms 256 KB OK (11 queries)
11 Correct 0 ms 256 KB OK (4 queries)
12 Correct 0 ms 256 KB OK (5 queries)
13 Correct 0 ms 256 KB OK (12 queries)
14 Incorrect 0 ms 256 KB Integer parameter [name=k] equals to -17, violates the range [1, 44]
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (5 queries)
2 Correct 0 ms 256 KB OK (7 queries)
3 Correct 0 ms 256 KB OK (10 queries)
4 Correct 1 ms 252 KB OK (26 queries)
5 Correct 0 ms 256 KB OK (13 queries)
6 Correct 0 ms 256 KB OK (3 queries)
7 Correct 1 ms 256 KB OK (18 queries)
8 Correct 0 ms 256 KB OK (8 queries)
9 Correct 1 ms 256 KB OK (10 queries)
10 Correct 0 ms 256 KB OK (11 queries)
11 Correct 0 ms 256 KB OK (4 queries)
12 Correct 0 ms 256 KB OK (5 queries)
13 Correct 0 ms 256 KB OK (12 queries)
14 Incorrect 0 ms 256 KB Integer parameter [name=k] equals to -17, violates the range [1, 44]
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (5 queries)
2 Correct 0 ms 256 KB OK (7 queries)
3 Correct 0 ms 256 KB OK (10 queries)
4 Correct 1 ms 252 KB OK (26 queries)
5 Correct 0 ms 256 KB OK (13 queries)
6 Correct 0 ms 256 KB OK (3 queries)
7 Correct 1 ms 256 KB OK (18 queries)
8 Correct 0 ms 256 KB OK (8 queries)
9 Correct 1 ms 256 KB OK (10 queries)
10 Correct 0 ms 256 KB OK (11 queries)
11 Correct 0 ms 256 KB OK (4 queries)
12 Correct 0 ms 256 KB OK (5 queries)
13 Correct 0 ms 256 KB OK (12 queries)
14 Incorrect 0 ms 256 KB Integer parameter [name=k] equals to -17, violates the range [1, 44]
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (5 queries)
2 Correct 0 ms 256 KB OK (7 queries)
3 Correct 0 ms 256 KB OK (10 queries)
4 Correct 1 ms 252 KB OK (26 queries)
5 Correct 0 ms 256 KB OK (13 queries)
6 Correct 0 ms 256 KB OK (3 queries)
7 Correct 1 ms 256 KB OK (18 queries)
8 Correct 0 ms 256 KB OK (8 queries)
9 Correct 1 ms 256 KB OK (10 queries)
10 Correct 0 ms 256 KB OK (11 queries)
11 Correct 0 ms 256 KB OK (4 queries)
12 Correct 0 ms 256 KB OK (5 queries)
13 Correct 0 ms 256 KB OK (12 queries)
14 Incorrect 0 ms 256 KB Integer parameter [name=k] equals to -17, violates the range [1, 44]
15 Halted 0 ms 0 KB -