답안 #1112147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112147 2024-11-13T17:08:33 Z vako_p Zagrade (COI20_zagrade) C++14
0 / 100
9 ms 592 KB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back

const int mxN = 1e6 + 5;
ll n,a[mxN];
stack<ll> st;
string s;

ll check(ll a, ll b){
	assert(a < b);
	ll curr = 0;
	for(int i = a - 1; i < b; i++){
		if(s[i] == '(') curr++;
		else curr--;
		if(curr < 0){
			cout << 0 << endl;
			return 0;
		}
	}
	if(curr != 0){
		cout << 0 << endl;
		return 0;
	}
	cout << 1 << endl;
	return 1;
}

void init(){
	cin >> s;
//	for(int i = 0; i < n / 2; i++) s += "()";
//	random_device rd;
//	mt19937_64 gen(rd());
//	uniform_int_distribution<ll> dis(0, n - 1);
//	for(int i = 1; i < n - 1; i++) swap(s[i], s[dis(gen)]);
//	cout << s << endl;
}

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	
//	init();
	
	ll cnt = n / 2; 
	st.push(1);
 	for(int i = 2; i <= n; i++){
 		ll l = st.top(); 
		cout << "? " << l << ' ' << i << endl;
		ll ans;
		cin >> ans;
//		ans = check(l, i);
		if(ans){
			a[l] = 1;
			a[i] = 2;
			cnt--;
		 	st.pop();
		}
		else st.push(i);
		if(st.empty()) st.push(++i);
	}
	ll val = 2;
	cout << "! ";
	for(int i = 1; i <= n; i++){
		if(!a[i]){
			cnt--;
			a[i] = val;
			if(cnt == 0) val = 1;
		}
		if(a[i] == 1) cout << '(';
		else cout << ')';
	}
	cout.flush();
//	cout << endl << "  " << s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
3 Incorrect 9 ms 464 KB Mismatch at position 2. Expected (, found )
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 512 KB Mismatch at position 2. Expected (, found )
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -