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 int long long
# define fir first
# define sec second
# define pb push_back
const int cnst = 2e5+5;
bool mutipletestcase = 0;
bool debug = 1;
string checker;
int find(int x, int y) {
int temp = 0;
for(int i = x-1; i<y; i++) {
if(checker[i] == '(') temp++;
else temp--;
if(temp < 0) return 0;
}
return temp == 0;
}
int ask(int l, int r) {
cout << "? " << l << " " << r << endl;
int a;
if(!debug) cin >> a;
else a = find(l, r);
return a;
}
void solve() {
int n, q; cin >> n >> q;
string ans = "(";
if(debug) cin >> checker;
stack<int> st;
st.push(1); st.push(1);
for(int i = 2; i<=n; i++) {
bool a = ask(st.top(), i);
if(a) st.pop(), ans += ')';
else ans += '(', st.push(i);
}
cout << "? " << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# | 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... |