# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727408 | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 9 ms | 596 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<iostream>
#include<vector>
#include<queue>
using namespace std;
string naw;
vector<pair<int,int>>ab;
vector<int>juzwyb,gdziedr;
int t,n;
void rozw()
{
scanf("%d",&n);
cin>>naw;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod1;
queue<int>dod2;
ab.resize(n);
juzwyb.resize(n<<1);
gdziedr.resize(n<<1);
for(int i=0;i<n;++i)
{
scanf("%d%d",&ab[i].first,&ab[i].second);
--ab[i].first;
--ab[i].second;
gdziedr[ab[i].first]=ab[i].second;
gdziedr[ab[i].second]=ab[i].first;
}
int ile=0;
for(int i=0;i<2*n;++i)
{
if(naw[gdziedr[i]]==naw[i])
{
if(naw[i]=='('&&i<gdziedr[i])
{
juzwyb[i]=t;
juzwyb[gdziedr[i]]=-t;
++ile;
}
else if(naw[i]==')'&&i>gdziedr[i])
{
juzwyb[i]=t;
juzwyb[gdziedr[i]]=-t;
--ile;
}
}
else
{
if(juzwyb[i]!=-t&&juzwyb[i]!=t)
{
if(naw[i]=='(')
{
juzwyb[i]=-t;
juzwyb[gdziedr[i]]=t;
dod1.push({i,gdziedr[i]});
}
else
{
juzwyb[i]=t;
juzwyb[gdziedr[i]]=-t;
--ile;
dod1.push({gdziedr[i],i});
}
}
else
{
if(juzwyb[i]==t)
{
if(naw[i]==')')
{
--ile;
dod2.push(i);
}
else
++ile;
}
else
{
if(naw[i]=='(')
dod2.push(gdziedr[i]);
}
}
}
if(ile<0)
{
while(!dod2.empty())
{
if(juzwyb[dod2.front()]!=-t)
break;
dod2.pop();
}
if(dod2.empty())
{
while(!dod1.empty())
{
if(juzwyb[dod1.top().second]!=-t)
break;
dod1.pop();
}
if(dod1.empty())
{
printf("-1\n");
return;
}
juzwyb[dod1.top().second]=-t;
juzwyb[dod1.top().first]=t;
++ile;
dod1.pop();
}
else
{
juzwyb[dod2.front()]=-t;
juzwyb[gdziedr[dod2.front()]]=t;
dod2.pop();
ile+=2;
}
}
}
if(ile!=0)
{
printf("-1\n");
return;
}
for(int i=0;i<n;++i)
{
if(juzwyb[ab[i].first]==t)
printf("0 ");
else
printf("1 ");
}
printf("\n");
}
int main()
{
ios_base::sync_with_stdio(0);
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... |