This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Zadanie: Zagrade
Autor: Tomasz Kwiatkowski
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int L[MAXN];
bool correct(int l, int r)
{
cout << "? " << l + 1 << ' ' << r + 1 << '\n';
cout.flush();
bool ans;
cin >> ans;
return ans;
}
void solve()
{
int N, Q;
cin >> N >> Q;
for (int i = 1; i < N; ++i)
L[i] = i - 1;
int par_left = N;
string ans(N, '#');
for (int i = 1; i < N; ++i) {
if (correct(L[i], i)) {
ans[L[i]] = '(';
ans[i] = ')';
par_left -= 2;
L[i + 1] = L[L[i]];
}
}
int k = 0;
for (int i = 0; i < N; ++i) {
if (ans[i] == '#')
ans[i] = (++k <= par_left/2 ? ')' : '(');
}
cout << "! " << ans << '\n';
cout.flush();
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0);
solve();
return 0;
}
# | 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... |