# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585050 | MetalPower | Zagrade (COI20_zagrade) | C++14 | 872 ms | 1020 KiB |
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;
int query(int l, int r){
cout << "? " << l + 1 << " " << r + 1 << endl;
int q; cin >> q; return q;
}
int N, Q;
vector<int> st;
vector<char> v;
int main(){
cin >> N >> Q;
v.resize(N, '-');
for(int i = 0; i < N; i++){
if(!st.empty()){
if(query(st.back(), i) == 1){
v[st.back()] = '(', v[i] = ')';
st.pop_back();
}else{
st.push_back(i);
}
}else{
st.push_back(i);
}
}
for(int i = 0; i < st.size() / 2; i++) v[st[i]] = ')';
for(int i = st.size() / 2; i < st.size(); i++) v[st[i]] = '(';
cout << "! ";
for(int i = 0; i < N; i++) cout << v[i];
cout << endl;
}
Compilation message (stderr)
# | 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... |