Submission #1033086

# Submission time Handle Problem Language Result Execution time Memory
1033086 2024-07-24T12:40:16 Z goodspeed0208 Colors (BOI20_colors) C++14
0 / 100
0 ms 344 KB
#include<bits/stdc++.h>
using namespace std;
 
signed main() {
	int n;
	cin >> n;
	set<int>st;
	
	int c;
	if (n == 2) {
		cout << "? 1" << endl; cin >> c;
		cout << "? 2" << endl; cin >> c;
		if (c == 1) cout << "= 1" << endl;
		else cout << "= 2" << endl;
		return 0;
	} else if (n == 3) {
		cout << "? 2" << endl; cin >> c;
		cout << "? 3" << endl; cin >> c;
		if (c == 1) cout << "= 1" << endl;
		else {
			cout << "? 1" << endl; cin >> c;
			if (c == 1) cout << "= 2" << endl;
			else cout << "= 3" << endl;
		}
		return 0;
		
	}
	int l = 2, r = n+3, t = 0, ans = n, end = 0;
	//if (n == 3) r = 5;
	cout << "? " << l << "\n"; st.insert(l);
	cin >> c;
	while (r - l > 4) {
		if (t) {
			l += 4;
			assert(st.find(l) == st.end());
			cout << "? " << l << endl; st.insert(l);
		} else {
			r -= 4;
			assert(st.find(r) == st.end());
			cout << "? " << r << endl; st.insert(r);
		}
		cin >> c;
		if (c == 0) break;
		else {
			ans = min(ans, r - l);
			if (ans <= 4) break;
		}
		t ^= 1;
	}
	if (c == 1) {
		while (ans > 1) {
			if (t) {
				r--;
				assert(st.find(r) == st.end());
				cout << "? " << r << endl;
			} else {
				l++;
				assert(st.find(l) == st.end());
				cout << "? " << l << endl;
			}
			t ^= 1;
			cin >> c;
			if (c == 1) ans = r - l;
			else break;
		}
		cout << "= " << ans << endl;
		return 0;
	}
	while (c == 0) {
		if (t) {
			r++;
			assert(st.find(r) == st.end());
			cout << "? " << r << endl; st.insert(r);
		} else {
			l--;
			assert(st.find(l) == st.end());
			cout << "? " << l << endl; st.insert(l);
		}
		t ^= 1;
		cin >> c;
		if (c == 1) {
			ans = min(ans, r - l);
			end = 1;
		}
		if (c == 0 && (r - l == ans-1)) {
			end = 1;
			break;
		}
	}
	cout << "= " << ans << endl;
}
 

Compilation message

Colors.cpp: In function 'int main()':
Colors.cpp:28:38: warning: variable 'end' set but not used [-Wunused-but-set-variable]
   28 |  int l = 2, r = n+3, t = 0, ans = n, end = 0;
      |                                      ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (3 queries)
2 Runtime error 0 ms 344 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (3 queries)
2 Runtime error 0 ms 344 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (3 queries)
2 Runtime error 0 ms 344 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (3 queries)
2 Runtime error 0 ms 344 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB OK (3 queries)
2 Runtime error 0 ms 344 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -