This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long, long long>
int n,q,sisa;
stack<int> st;
char s[100069];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int i,j;
cin>>n>>q;
sisa = n/2;
for(i=1;i<=n and q;i++)
{
if(st.empty())
{
st.push(i);
continue;
}
cout<<"? "<<st.top()<<" "<<i<<'\n';
cout.flush();
bool valid;
cin>>valid;
if(valid)
{
s[st.top()] = '(';
s[i] = ')';
sisa--;
st.pop();
}
else
{
st.push(i);
}
q--;
}
for(j=i;j<=n;j++) st.push(j);
while(!st.empty())
{
int x = st.top();
st.pop();
if(sisa)
{
s[x] = '(';
sisa--;
}
else
{
s[x] = ')';
}
}
cout<<"! ";
for(i=1;i<=n;i++)
{
cout<<s[i];
if(i == n)
{
cout<<'\n';
}
}
// )())(()(
}
# | 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... |