Submission #12183

#TimeUsernameProblemLanguageResultExecution timeMemory
12183imsifile전선 연결하기 (GA9_wire)C++98
0 / 100
0 ms7656 KiB
#include<stdio.h> #include<set> using namespace std; struct pa { int ix, ep; bool operator< (const pa& c) const { return ep<c.ep; } }im; int n, ba[600060], ix2[300030], cnt, fl; int ncn[300030], par[300030]; bool chk[300030], pbit[300030], xo; set<pa> sets; set<pa>::iterator it; int root(int ix){ while(par[ix]!=-1)xo^=pbit[ix], ix=par[ix]; return ix; } void con(int a, int b){ xo=1; a=root(a), b=root(b); if(a==b && xo)fl=1; if(a!=b){ if(ncn[a]>=ncn[b])par[b]=a, ncn[a]+=ncn[b], pbit[b]=xo; else par[a]=b, ncn[b]+=ncn[a], pbit[a]=xo; } } int main(){ int i, j; scanf("%d", &n); for(i=0; i<2*n; i++){ scanf("%d", &ba[i]); ix2[ba[i]]=i; } for(i=1; i<=n; i++)ncn[i]=1, par[i]=-1; for(i=0; i<2*n; i++){ im.ep=ix2[ba[i]], im.ix=ba[i]; if(im.ep==i)sets.erase(im); else{ for(it=sets.begin(); it!=sets.end(); it++){ if((*it).ep > im.ep)break; con(ba[i], (*it).ix); cnt++; if(cnt>=n || fl){ puts("IMPOSSIBLE"); return 0; } } sets.insert(im); } } for(i=1; i<=n; i++){ xo=0, root(i); chk[i]=xo; } for(i=0; i<2*n; i++)printf("%c", chk[ba[i]]?'v':'^'); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...