이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,q,temp;
ll a,cnt;
stack<ll> st;
char ans[100100];
int main() {
cin >> n >> q;
FOR(1,i,n) {
if(!st.empty()) {
cout << "? " << st.top() << " " << i << endl;
cin >> a;
if(a == 1) {
ans[st.top()] = '(';
ans[i] = ')';
cnt += 2;
st.pop();
}
else {
st.push(i);
}
}
else {
st.push(i);
}
}
cnt = n - cnt;
temp = cnt;
FOR(1,i,n) {
if(temp > cnt/2 && ans[i] != ')' && ans[i] != '(') {
ans[i] = ')';
temp--;
}
else if(ans[i] != ')' && ans[i] != '(') {
ans[i] = '(';
}
}
cout << "! ";
FOR(1,i,n) {
cout << ans[i];
}
cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |