# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546245 | yutabi | Zagrade (COI20_zagrade) | C++14 | 707 ms | 4064 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;
struct pos
{
int ptr=0;
pos* l=NULL;
pos* r=NULL;
};
pos* bas=new pos;
void rm(pos* nd)
{
if(nd->l!=NULL)
{
nd->l->r=nd->r;
}
if(nd->r!=NULL)
{
nd->r->l=nd->l;
}
if(nd==bas && nd->r!=NULL)
{
bas=nd->r;
}
}
int n;
int q;
int ans[100007];
int k;
int main()
{
scanf("%d %d",&n,&q);
pos* curr=bas;
for(int i=1;i<n;i++)
{
pos* nw=new pos;
nw->ptr=i;
nw->l=curr;
curr->r=nw;
curr=nw;
}
curr=bas;
for(int i=0;i<n;i++)
{
if(curr->l!=NULL)
{
printf("? %d %d\n",(curr->l->ptr)+1,(curr->ptr)+1);
fflush(stdout);
int a;
scanf(" %d",&a);
if(a==1)
{
ans[curr->l->ptr]=1;
ans[curr->ptr]=2;
rm(curr->l);
rm(curr);
k+=2;
}
else if(a!=0)
{
return 0;
}
}
curr=curr->r;
}
curr=bas;
for(int i=0;i<n-k;i++)
{
if(i*2<n-k)
{
ans[curr->ptr]=2;
}
else
{
ans[curr->ptr]=1;
}
curr=curr->r;
}
printf("! ");
for(int i=0;i<n;i++)
{
if(ans[i]==1)
{
printf("(");
}
if(ans[i]==2)
{
printf(")");
}
}
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... |