답안 #810216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810216 2023-08-06T06:38:54 Z ymm Colors (BOI20_colors) C++17
0 / 100
300 ms 208 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

set<ll> S;
bool query(ll x)
{
	assert(!S.count(x));
	S.insert(x);
	int d;
	printf("? %lld\n", x+1);
	fflush(stdout);
	scanf("%d", &d);
	return d;
}


int main()
{
	ll n;
	scanf("%lld", &n);
	ll pos = n/2+1;
	query(pos);
	ll l = 1, r = n;
	while (l < r) {
		ll m0 = (l+r)/2;
		ll x = pos < n/2? 1: -1;
		//cerr << l << ' ' << r << ' ' << pos+1 << ' ' << m0 << '\n';
		ll m;
		for (ll i = 0;; ++i) {
			ll dard = i%2? i/2+1: -i/2;
			//ll dard = i%2? -i/2+1: i/2;
			ll pos2 = pos + x*(m0+dard);
			if (pos2 < 0 || n <= pos2 || S.count(pos2))
				continue;
			m = m0+dard;
			break;
		}
		if (query(pos = pos + x*m))
			r = m;
		else
			l = m+1;
	}
	printf("= %lld\n", l);
}

Compilation message

Colors.cpp: In function 'bool query(ll)':
Colors.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d", &d);
      |  ~~~~~^~~~~~~~~~
Colors.cpp: In function 'int main()':
Colors.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB OK (4 queries)
2 Execution timed out 3066 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB OK (4 queries)
2 Execution timed out 3066 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB OK (4 queries)
2 Execution timed out 3066 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB OK (4 queries)
2 Execution timed out 3066 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB OK (4 queries)
2 Execution timed out 3066 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -