답안 #12183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12183 2014-12-21T16:25:12 Z imsifile 전선 연결하기 (GA9_wire) C++
0 / 100
0 ms 7656 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7656 KB Output is correct
2 Correct 0 ms 7656 KB Output is correct
3 Correct 0 ms 7656 KB Output is correct
4 Correct 0 ms 7656 KB Output is correct
5 Correct 0 ms 7656 KB Output is correct
6 Correct 0 ms 7656 KB Output is correct
7 Correct 0 ms 7656 KB Output is correct
8 Correct 0 ms 7656 KB Output is correct
9 Correct 0 ms 7656 KB Output is correct
10 Correct 0 ms 7656 KB Output is correct
11 Correct 0 ms 7656 KB Output is correct
12 Correct 0 ms 7656 KB Output is correct
13 Correct 0 ms 7656 KB Output is correct
14 Correct 0 ms 7656 KB Output is correct
15 Correct 0 ms 7656 KB Output is correct
16 Correct 0 ms 7656 KB Output is correct
17 Correct 0 ms 7656 KB Output is correct
18 Correct 0 ms 7656 KB Output is correct
19 Correct 0 ms 7656 KB Output is correct
20 Correct 0 ms 7656 KB Output is correct
21 Correct 0 ms 7656 KB Output is correct
22 Correct 0 ms 7656 KB Output is correct
23 Correct 0 ms 7656 KB Output is correct
24 Correct 0 ms 7656 KB Output is correct
25 Correct 0 ms 7656 KB Output is correct
26 Correct 0 ms 7656 KB Output is correct
27 Correct 0 ms 7656 KB Output is correct
28 Correct 0 ms 7656 KB Output is correct
29 Correct 0 ms 7656 KB Output is correct
30 Correct 0 ms 7656 KB Output is correct
31 Correct 0 ms 7656 KB Output is correct
32 Correct 0 ms 7656 KB Output is correct
33 Correct 0 ms 7656 KB Output is correct
34 Correct 0 ms 7656 KB Output is correct
35 Incorrect 0 ms 7656 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -