# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730728 | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 27 ms | 3096 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;
#define f first
#define s second
#define pf printf
#define pii pair<int,int>
pii ab[200001];
char naw[200001];
int jb[200001],gr[200001];
int t,n;
void rozw()
{
scanf("%d",&n);
priority_queue<pii ,vector<pii >,greater<pii >>dod;
getchar();
for(int i=0;i<n*2;++i)
naw[i]=getchar();
for(int i=0;i<n;++i)
{
scanf("%d%d",&ab[i].f,&ab[i].s);
--ab[i].f;
--ab[i].s;
gr[ab[i].f]=ab[i].s;
gr[ab[i].s]=ab[i].f;
}
int ile=0;
for(int i=0;i<2*n;++i)
{
if(naw[gr[i]]==naw[i])
{
if(naw[i]=='('&&i<gr[i])
{
jb[i]=t;
jb[gr[i]]=-t;
++ile;
}
else if(naw[i]==')'&&i>gr[i])
{
jb[i]=t;
jb[gr[i]]=-t;
--ile;
}
}
else
{
if(jb[i]!=-t&&jb[i]!=t)
{
if(naw[i]=='(')
{
jb[i]=-t;
jb[gr[i]]=t;
dod.push({gr[i],i});
}
else
{
jb[i]=t;
jb[gr[i]]=-t;
--ile;
dod.push({gr[i],i});
}
}
else if(jb[i]==t)
{
ile++;
if(naw[i]==')')
ile-=2;
}
}
if(ile<0)
{
if(dod.empty())
{
pf("-1\n");
return;
}
jb[dod.top().s]*=-1;
jb[dod.top().f]*=-1;
++ile;
if(max(dod.top().f,dod.top().s)<=i)
++ile;
dod.pop();
}
}
if(ile!=0)
{
pf("-1\n");
return;
}
for(int i=0;i<n;++i)
{
if(jb[ab[i].f]==t)
pf("0 ");
else
pf("1 ");
}
pf("\n");
}
int main()
{
scanf("%d",&t);
while(t)
{
rozw();
--t;
}
}
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... |