답안 #1003917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003917 2024-06-20T19:57:56 Z vjudge1 Zagrade (COI20_zagrade) C++17
0 / 100
653 ms 2056 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define tii tuple<int,int,int,int,int>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

bool ask(int l, int r){
	cout << "? " << l << " " << r << endl;
	int rt; cin >> rt;
	return rt;
}


signed main(){
	int n,q; cin >> n >> q;
	vector<bool> small(n+5,0);
	vector<char> ans(n+5);

	for(int i=1; i<n; i++){
		small[i] = ask(i,i+1);
		if(small[i]) ans[i]='(', ans[i+1]=')';
	}

	vector<int> p(n+5,0), s(n+5,0);
	for(int i=1; i<=n; i++){
		p[i] = p[i-1]+1-small[i-1];
	}
	for(int i=n; i>0; i--){
		s[i] = s[i+1]+1-small[i];
	}

	int bp=-1;
	for(int i=1; i<n; i++){
		if(p[i]==s[i+1]){
			bp=i;
			break;
		}
	}

	for(int i=0; bp+i<n; i++){
		if(small[bp-i] || small[bp+i+1]) break;
		ans[bp-i]=')';
		ans[bp+i+1]='(';
	}

	assert(bp!=-1);
	cout << "! ";
	for(int i=1; i<=n; i++){
		if(ans[i]==')' || ans[i]=='(') cout << ans[i];
		else{
			if(i<bp) cout << "(";
			else cout << ")";
		}
	}
	cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 440 KB Output is correct
3 Incorrect 5 ms 436 KB Mismatch at position 10. Expected ), found (
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Incorrect 4 ms 344 KB Mismatch at position 4. Expected ), found (
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 542 ms 2056 KB Output is correct
3 Incorrect 544 ms 2056 KB Mismatch at position 16. Expected ), found (
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 581 ms 2056 KB Output is correct
3 Incorrect 653 ms 2056 KB Mismatch at position 4. Expected ), found (
4 Halted 0 ms 0 KB -