#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
//#define endl '\n'
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define pb push_back
const int mod = 1e7 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
stack<int> st;
st.push(0);
int n,q;
cin >> n >> q;
vector<char> a(n,'x');
bool valid;
int op=n/2,cl=n/2; // number of open bracket needed ..
for (int i=1;i<n;i++){
cout << "? " << st.top()+1 << ' ' << i+1 << endl;
cin >> valid;
if (valid){
a[st.top()] = '(';
a[i] = ')';
op--;cl--;
st.pop();
}
else {
st.push(i);
}
}
// now they are )))(((
for (int i=0;i<op;i++){
a[st.top()] = '(';
st.pop();
}
for (int i=0;i<cl;i++){
a[st.top()] = ')';
st.pop();
}
cout << "! "; for (auto it : a) cout << it ;
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
13 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
880 ms |
1328 KB |
Output is correct |
3 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |