# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1154338 | MinhTuan11 | Zagrade (COI20_zagrade) | C++20 | 228 ms | 1356 KiB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
const int N = 2e5 + 5;
const int K = 1e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
stack<int> st;
int ask(int l, int r) {
cout << "? " << l << ' ' << r << endl;
int rep;
cin >> rep;
return rep;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if(ifstream("file.inp")){
freopen("file.inp", "r", stdin);
freopen("file.out", "w", stdout);
}
cin >> n >> q;
string s(n, '.');
for(int i = 1; i <= n; i++) {
if(st.size() == 0) {
st.push(i);
continue;
}
int rep = ask(st.top(), i);
if(rep == 1) {
s[st.top() - 1] = '(';
s[i - 1] = ')';
st.pop();
}
else {
st.push(i);
}
}
int rem = st.size();
for(int i = 1; i <= rem / 2; i++) {
s[st.top() - 1] = '(';
st.pop();
}
for(int i = 1; i <= rem / 2; i++) {
s[st.top() - 1] = ')';
st.pop();
}
cout << "! " << s << endl;
return 0;
}
// tuntun172
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... |