답안 #1003765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003765 2024-06-20T17:08:09 Z vjudge1 Zagrade (COI20_zagrade) C++17
100 / 100
579 ms 2184 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

const int MAXN = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

void solve(){
	int n, q; cin >> n >> q;
	
	stack<int> last;
	int curr=1;
	string res;
	
	int val=0;
	vector<int> skip(n, 0);
	while(curr<=n){
		if(last.empty()){
			res+='(';
			last.push(curr);
			curr++;
			continue;
		}
		
		cout << "? " << last.top() << " " << curr << endl;
		int aux; cin >> aux;
		
		if(aux){
			skip[last.top()-1]=1; skip[curr-1]=1;
			last.pop();
			res+=')';
			val++;
		}
		else{
			last.push(curr);
			res+='(';
		}
		
		curr++;
	}
	
	for(int i=0;i<n && val<(n>>1);i++){
		if(skip[i]) continue;
		res[i]=')';
		val++;
	}
	
	cout << "! " << res << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int tt=1;
	//~ cin >> tt;
	while(tt--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 6 ms 452 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 4 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 4 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 6 ms 460 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 297 ms 1200 KB Output is correct
3 Correct 561 ms 1100 KB Output is correct
4 Correct 564 ms 1468 KB Output is correct
5 Correct 579 ms 1464 KB Output is correct
6 Correct 578 ms 1644 KB Output is correct
7 Correct 558 ms 1672 KB Output is correct
8 Correct 566 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 516 ms 2184 KB Output is correct
3 Correct 546 ms 1484 KB Output is correct
4 Correct 539 ms 1620 KB Output is correct
5 Correct 537 ms 1540 KB Output is correct
6 Correct 539 ms 1612 KB Output is correct
7 Correct 537 ms 1868 KB Output is correct
8 Correct 517 ms 1524 KB Output is correct