# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
730703 | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 26 ms | 3872 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
char *naw;
vector<pair<int,int>>ab;
vector<int>juzwyb,gdziedr;
int t,n;
void rozw()
{
scanf("%d",&n);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod;
delete[] naw;
naw = new char[n<<1];
ab.resize(n);
juzwyb.resize(n<<1);
gdziedr.resize(n<<1);
scanf("%s",naw);
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;
dod.push({i,gdziedr[i]});
}
else
{
juzwyb[i]=t;
juzwyb[gdziedr[i]]=-t;
--ile;
dod.push({i,gdziedr[i]});
}
}
else
{
if(juzwyb[i]==t)
{
if(naw[i]==')')
--ile;
else
++ile;
}
}
}
if(ile<0)
{
if(dod.empty())
{
printf("-1\n");
return;
}
juzwyb[dod.top().second]*=-1;
juzwyb[dod.top().first]*=-1;
++ile;
if(max(dod.top().first,dod.top().second)<=i)
++ile;
dod.pop();
}
}
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()
{
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... |