# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
730713 | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 29 ms | 2476 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
pair<int,int>ab[100001];
char naw[100001];
int jb[100001],gr[100001];
int t,n;
void rozw()
{
scanf("%d",&n);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod;
char wcz=getchar();
while(wcz!='('&&wcz!=')')
wcz=getchar();
for(int i=0;i<(n<<1);++i)
{
naw[i]=wcz;
wcz=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)
{
if(naw[i]==')')
--ile;
else
++ile;
}
}
}
if(ile<0)
{
if(dod.empty())
{
printf("-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)
{
printf("-1\n");
return;
}
for(int i=0;i<n;++i)
{
if(jb[ab[i].f]==t)
printf("0 ");
else
printf("1 ");
}
printf("\n");
}
int main()
{
ios_base::sync_with_stdio(0);
scanf("%d",&t);
while(t)
{
rozw();
--t;
}
}
컴파일 시 표준 에러 (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... |