# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367725 | arnold518 | Zagrade (COI20_zagrade) | C++14 | 1256 ms | 6964 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N, Q;
map<pii, int> MM;
bool query(int l, int r)
{
if(MM.find({l, r})!=MM.end()) return MM[{l, r}];
printf("? %d %d\n", l, r);
fflush(stdout);
int t;
scanf("%d", &t);
MM[{l, r}]=t;
return t;
}
char ans[MAXN+10];
int main()
{
scanf("%d%d", &N, &Q);
vector<int> V;
for(int i=1; i<=N; i++)
{
if(V.empty()) V.push_back(i);
else
{
int t=V.back();
if(query(t, i))
{
ans[t]='(';
ans[i]=')';
V.pop_back();
}
else
{
V.push_back(i);
}
}
}
printf("! %s\n", ans+1);
fflush(stdout);
}
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... |