답안 #1003855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003855 2024-06-20T19:05:27 Z Lobo Zagrade (COI20_zagrade) C++17
100 / 100
657 ms 5924 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const int maxn = 5e5+10;
const int inf = 1e18+10;
int n;
int query(int l, int r) {
	if(l > r) return 0;
	if(l < 0 or r >= n) return 0;
	cout << "? " << l+1 << " " << r+1 << endl;
	cout.flush(); 
	int x; cin >> x;
	return x;
}

int32_t main() {
	// #ifndef ONLINE_JUDGE
	// freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
	// #endif

	int q;
	cin >> n >> q;
	vector<int> ans(n,0);
	int antok = -inf;
	int pos = 0;
	int qtd = n/2;

	set<int> ids;
	for(int i = 0; i < n; i++) ids.insert(i);

	for(int r = 1; r < n; r++) {
		auto it = ids.find(r);
		if(it == ids.begin()) continue;
		it = prev(it);
		int l = *it;

		if(query(l,r)) {
			ans[l] = +1;
			ans[r] = -1;
			ids.erase(l);
			ids.erase(r);
			qtd--;
		}
	}

	// while(pos+1 < n) {
	// 	int l = pos+1;
	// 	int r = pos;
	// 	while(l-1 > antok && query(l-1,r+1)) {
	// 		l--;
	// 		r++;
	// 		ans[l] = +1;
	// 		ans[r] = -1;
	// 		qtd--;
	// 	}
	// 	if(l <= r) antok = r;
	// 	pos = r+1;
	// }

	for(int i = 0; i < n; i++) {
		if(ans[i] == 0) {
			if(qtd == 0) {
				ans[i] = +1;
			}
			else {
				qtd--;
				ans[i] = -1;
			}
		}
	}

	cout << "! ";
	for(int i = 0; i < n; i++) {
		if(ans[i] == -1) cout << ')';
		else cout << '(';
	}
	cout.flush();
}

Compilation message

zagrade.cpp: In function 'int32_t main()':
zagrade.cpp:30:6: warning: unused variable 'antok' [-Wunused-variable]
   30 |  int antok = -inf;
      |      ^~~~~
zagrade.cpp:31:6: warning: unused variable 'pos' [-Wunused-variable]
   31 |  int pos = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 303 ms 5924 KB Output is correct
3 Correct 652 ms 5720 KB Output is correct
4 Correct 552 ms 5720 KB Output is correct
5 Correct 577 ms 5720 KB Output is correct
6 Correct 610 ms 5720 KB Output is correct
7 Correct 611 ms 5720 KB Output is correct
8 Correct 569 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 593 ms 5720 KB Output is correct
3 Correct 529 ms 5720 KB Output is correct
4 Correct 540 ms 5716 KB Output is correct
5 Correct 628 ms 5772 KB Output is correct
6 Correct 657 ms 5720 KB Output is correct
7 Correct 618 ms 5720 KB Output is correct
8 Correct 632 ms 5720 KB Output is correct