답안 #63251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63251 2018-08-01T07:04:03 Z 김세빈(#1833) Alternating Current (BOI18_alternating) C++11
55 / 100
3000 ms 18972 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

vector <int> L[101010], V[101010];
vector <int> X[101010], Y[101010];
set <int> S;
pii P[101010];
int chk[101010], ans[101010];
int n, m;

void die() { printf("impossible\n"); exit(0); }

void dfs(int p, int c)
{
	chk[p] = 2; ans[p] = c;
	for(int &t: V[p]){
		if(chk[t] == 1) dfs(t, !c);
		else if(ans[t] == ans[p]) die();
	}
}

int main()
{
	int i, j, s, e, x, y, a, b;
	
	scanf("%d%d", &n, &m);
	
	for(i=1; i<=m; i++){
		scanf("%d%d", &a, &b);
		b ++; if(b > n) b -= n;
		P[i] = pii(a, b);
		if(a < b){
			L[a].push_back(i);
			L[b].push_back(-i);
		}
		else{
			L[1].push_back(i);
			L[b].push_back(-i);
			L[a].push_back(i);
		}
	}
	
	for(i=1; i<=n; i++){
		for(int &t: L[i]){
			if(t > 0) S.insert(t);
			else S.erase(-t);
		}
		
		if(S.size() == 2){
			a = *S.begin(); b = *next(S.begin());
			V[a].push_back(b);
			V[b].push_back(a);
			chk[a] = 1; chk[b] = 1;
		}
		else if(S.size() == 1) die();
	}
	
	for(i=1; i<=m; i++){
		if(chk[i] == 1) dfs(i, 0);
	}
	
	x = 1;
	
	for(i=1; i<=m; i++){
		if(chk[i]){
			if(ans[i] == 1) x = i;
		}
	}
	
	ans[x] = 1;
	s = P[x].first;
	
	for(i=1; i<=m; i++){
		P[i].first = (P[i].first - s + n) % n + 1;
		P[i].second = (P[i].second - s + n) % n + 1;
		if(P[i].first >= P[i].second) P[i].second += n;
		
		if(chk[i] && ans[i] == 1) X[P[i].first].push_back(i);
		else if(!chk[i]) Y[P[i].first].push_back(i);
	}
	
	s = 1; e = P[x].second; y = -1;
	
	for(i=1; i<=n; i++){
		for(int &t: X[i]) e = max(e, P[t].second);
		
		if(i == e){
			y = -1;
			for(j=s; j<=e; j++){
				for(int &t: Y[j]){
					if(P[t].second > e) y = t;
				}
			}
			if(y == -1) die();
			
			ans[y] = 1;
			e = P[y].second;
			i = P[y].first;
			y = -1;
		}
	}
	
	for(i=1; i<=m; i++) printf("%d", ans[i]);
	printf("\n");
	
	return 0;
}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
alternating.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 13 ms 9848 KB Output is correct
3 Correct 13 ms 9908 KB Output is correct
4 Correct 13 ms 10088 KB Output is correct
5 Correct 14 ms 10088 KB Output is correct
6 Correct 15 ms 10088 KB Output is correct
7 Correct 11 ms 10088 KB Output is correct
8 Correct 13 ms 10092 KB Output is correct
9 Correct 11 ms 10092 KB Output is correct
10 Correct 13 ms 10092 KB Output is correct
11 Correct 11 ms 10092 KB Output is correct
12 Correct 12 ms 10200 KB Output is correct
13 Correct 13 ms 10200 KB Output is correct
14 Correct 11 ms 10200 KB Output is correct
15 Correct 11 ms 10200 KB Output is correct
16 Correct 11 ms 10200 KB Output is correct
17 Correct 12 ms 10200 KB Output is correct
18 Correct 13 ms 10200 KB Output is correct
19 Correct 11 ms 10200 KB Output is correct
20 Correct 13 ms 10200 KB Output is correct
21 Correct 13 ms 10200 KB Output is correct
22 Correct 13 ms 10200 KB Output is correct
23 Correct 13 ms 10200 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 14 ms 10324 KB Output is correct
26 Correct 14 ms 10324 KB Output is correct
27 Correct 14 ms 10324 KB Output is correct
28 Correct 15 ms 10324 KB Output is correct
29 Correct 12 ms 10324 KB Output is correct
30 Correct 15 ms 10324 KB Output is correct
31 Correct 10 ms 10324 KB Output is correct
32 Correct 12 ms 10324 KB Output is correct
33 Correct 13 ms 10324 KB Output is correct
34 Correct 13 ms 10324 KB Output is correct
35 Correct 11 ms 10324 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 17 ms 10324 KB Output is correct
38 Correct 13 ms 10324 KB Output is correct
39 Correct 11 ms 10324 KB Output is correct
40 Correct 11 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 13 ms 9848 KB Output is correct
3 Correct 13 ms 9908 KB Output is correct
4 Correct 13 ms 10088 KB Output is correct
5 Correct 14 ms 10088 KB Output is correct
6 Correct 15 ms 10088 KB Output is correct
7 Correct 11 ms 10088 KB Output is correct
8 Correct 13 ms 10092 KB Output is correct
9 Correct 11 ms 10092 KB Output is correct
10 Correct 13 ms 10092 KB Output is correct
11 Correct 11 ms 10092 KB Output is correct
12 Correct 12 ms 10200 KB Output is correct
13 Correct 13 ms 10200 KB Output is correct
14 Correct 11 ms 10200 KB Output is correct
15 Correct 11 ms 10200 KB Output is correct
16 Correct 11 ms 10200 KB Output is correct
17 Correct 12 ms 10200 KB Output is correct
18 Correct 13 ms 10200 KB Output is correct
19 Correct 11 ms 10200 KB Output is correct
20 Correct 13 ms 10200 KB Output is correct
21 Correct 13 ms 10200 KB Output is correct
22 Correct 13 ms 10200 KB Output is correct
23 Correct 13 ms 10200 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 14 ms 10324 KB Output is correct
26 Correct 14 ms 10324 KB Output is correct
27 Correct 14 ms 10324 KB Output is correct
28 Correct 15 ms 10324 KB Output is correct
29 Correct 12 ms 10324 KB Output is correct
30 Correct 15 ms 10324 KB Output is correct
31 Correct 10 ms 10324 KB Output is correct
32 Correct 12 ms 10324 KB Output is correct
33 Correct 13 ms 10324 KB Output is correct
34 Correct 13 ms 10324 KB Output is correct
35 Correct 11 ms 10324 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 17 ms 10324 KB Output is correct
38 Correct 13 ms 10324 KB Output is correct
39 Correct 11 ms 10324 KB Output is correct
40 Correct 11 ms 10324 KB Output is correct
41 Correct 12 ms 10324 KB Output is correct
42 Correct 13 ms 10324 KB Output is correct
43 Correct 14 ms 10324 KB Output is correct
44 Correct 13 ms 10324 KB Output is correct
45 Correct 12 ms 10324 KB Output is correct
46 Correct 11 ms 10324 KB Output is correct
47 Correct 12 ms 10324 KB Output is correct
48 Correct 12 ms 10324 KB Output is correct
49 Correct 10 ms 10324 KB Output is correct
50 Correct 13 ms 10324 KB Output is correct
51 Correct 11 ms 10324 KB Output is correct
52 Correct 11 ms 10324 KB Output is correct
53 Correct 13 ms 10324 KB Output is correct
54 Correct 11 ms 10324 KB Output is correct
55 Correct 11 ms 10324 KB Output is correct
56 Correct 13 ms 10324 KB Output is correct
57 Correct 11 ms 10324 KB Output is correct
58 Correct 13 ms 10324 KB Output is correct
59 Correct 11 ms 10324 KB Output is correct
60 Correct 14 ms 10324 KB Output is correct
61 Correct 12 ms 10324 KB Output is correct
62 Correct 13 ms 10324 KB Output is correct
63 Correct 13 ms 10324 KB Output is correct
64 Correct 12 ms 10324 KB Output is correct
65 Correct 13 ms 10324 KB Output is correct
66 Correct 11 ms 10324 KB Output is correct
67 Correct 10 ms 10324 KB Output is correct
68 Correct 12 ms 10324 KB Output is correct
69 Correct 12 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 13 ms 9848 KB Output is correct
3 Correct 13 ms 9908 KB Output is correct
4 Correct 13 ms 10088 KB Output is correct
5 Correct 14 ms 10088 KB Output is correct
6 Correct 15 ms 10088 KB Output is correct
7 Correct 11 ms 10088 KB Output is correct
8 Correct 13 ms 10092 KB Output is correct
9 Correct 11 ms 10092 KB Output is correct
10 Correct 13 ms 10092 KB Output is correct
11 Correct 11 ms 10092 KB Output is correct
12 Correct 12 ms 10200 KB Output is correct
13 Correct 13 ms 10200 KB Output is correct
14 Correct 11 ms 10200 KB Output is correct
15 Correct 11 ms 10200 KB Output is correct
16 Correct 11 ms 10200 KB Output is correct
17 Correct 12 ms 10200 KB Output is correct
18 Correct 13 ms 10200 KB Output is correct
19 Correct 11 ms 10200 KB Output is correct
20 Correct 13 ms 10200 KB Output is correct
21 Correct 13 ms 10200 KB Output is correct
22 Correct 13 ms 10200 KB Output is correct
23 Correct 13 ms 10200 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 14 ms 10324 KB Output is correct
26 Correct 14 ms 10324 KB Output is correct
27 Correct 14 ms 10324 KB Output is correct
28 Correct 15 ms 10324 KB Output is correct
29 Correct 12 ms 10324 KB Output is correct
30 Correct 15 ms 10324 KB Output is correct
31 Correct 10 ms 10324 KB Output is correct
32 Correct 12 ms 10324 KB Output is correct
33 Correct 13 ms 10324 KB Output is correct
34 Correct 13 ms 10324 KB Output is correct
35 Correct 11 ms 10324 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 17 ms 10324 KB Output is correct
38 Correct 13 ms 10324 KB Output is correct
39 Correct 11 ms 10324 KB Output is correct
40 Correct 11 ms 10324 KB Output is correct
41 Correct 12 ms 10324 KB Output is correct
42 Correct 13 ms 10324 KB Output is correct
43 Correct 14 ms 10324 KB Output is correct
44 Correct 13 ms 10324 KB Output is correct
45 Correct 12 ms 10324 KB Output is correct
46 Correct 11 ms 10324 KB Output is correct
47 Correct 12 ms 10324 KB Output is correct
48 Correct 12 ms 10324 KB Output is correct
49 Correct 10 ms 10324 KB Output is correct
50 Correct 13 ms 10324 KB Output is correct
51 Correct 11 ms 10324 KB Output is correct
52 Correct 11 ms 10324 KB Output is correct
53 Correct 13 ms 10324 KB Output is correct
54 Correct 11 ms 10324 KB Output is correct
55 Correct 11 ms 10324 KB Output is correct
56 Correct 13 ms 10324 KB Output is correct
57 Correct 11 ms 10324 KB Output is correct
58 Correct 13 ms 10324 KB Output is correct
59 Correct 11 ms 10324 KB Output is correct
60 Correct 14 ms 10324 KB Output is correct
61 Correct 12 ms 10324 KB Output is correct
62 Correct 13 ms 10324 KB Output is correct
63 Correct 13 ms 10324 KB Output is correct
64 Correct 12 ms 10324 KB Output is correct
65 Correct 13 ms 10324 KB Output is correct
66 Correct 11 ms 10324 KB Output is correct
67 Correct 10 ms 10324 KB Output is correct
68 Correct 12 ms 10324 KB Output is correct
69 Correct 12 ms 10324 KB Output is correct
70 Correct 13 ms 10324 KB Output is correct
71 Correct 17 ms 10324 KB Output is correct
72 Correct 10 ms 10324 KB Output is correct
73 Correct 10 ms 10324 KB Output is correct
74 Correct 12 ms 10324 KB Output is correct
75 Correct 13 ms 10324 KB Output is correct
76 Correct 11 ms 10324 KB Output is correct
77 Correct 13 ms 10324 KB Output is correct
78 Correct 11 ms 10324 KB Output is correct
79 Correct 11 ms 10324 KB Output is correct
80 Correct 11 ms 10324 KB Output is correct
81 Correct 13 ms 10324 KB Output is correct
82 Correct 12 ms 10324 KB Output is correct
83 Correct 13 ms 10324 KB Output is correct
84 Correct 11 ms 10324 KB Output is correct
85 Correct 11 ms 10324 KB Output is correct
86 Correct 12 ms 10324 KB Output is correct
87 Correct 18 ms 10324 KB Output is correct
88 Correct 12 ms 10324 KB Output is correct
89 Correct 13 ms 10324 KB Output is correct
90 Correct 14 ms 10324 KB Output is correct
91 Correct 11 ms 10324 KB Output is correct
92 Correct 14 ms 10324 KB Output is correct
93 Correct 13 ms 10324 KB Output is correct
94 Correct 14 ms 10324 KB Output is correct
95 Correct 11 ms 10324 KB Output is correct
96 Correct 12 ms 10324 KB Output is correct
97 Correct 12 ms 10324 KB Output is correct
98 Correct 13 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 17940 KB Output is correct
2 Correct 15 ms 17940 KB Output is correct
3 Correct 35 ms 17940 KB Output is correct
4 Correct 79 ms 17940 KB Output is correct
5 Correct 151 ms 18444 KB Output is correct
6 Correct 87 ms 18444 KB Output is correct
7 Correct 166 ms 18444 KB Output is correct
8 Correct 19 ms 18444 KB Output is correct
9 Correct 14 ms 18444 KB Output is correct
10 Correct 158 ms 18972 KB Output is correct
11 Correct 123 ms 18972 KB Output is correct
12 Correct 124 ms 18972 KB Output is correct
13 Correct 13 ms 18972 KB Output is correct
14 Correct 13 ms 18972 KB Output is correct
15 Execution timed out 3094 ms 18972 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 13 ms 9848 KB Output is correct
3 Correct 13 ms 9908 KB Output is correct
4 Correct 13 ms 10088 KB Output is correct
5 Correct 14 ms 10088 KB Output is correct
6 Correct 15 ms 10088 KB Output is correct
7 Correct 11 ms 10088 KB Output is correct
8 Correct 13 ms 10092 KB Output is correct
9 Correct 11 ms 10092 KB Output is correct
10 Correct 13 ms 10092 KB Output is correct
11 Correct 11 ms 10092 KB Output is correct
12 Correct 12 ms 10200 KB Output is correct
13 Correct 13 ms 10200 KB Output is correct
14 Correct 11 ms 10200 KB Output is correct
15 Correct 11 ms 10200 KB Output is correct
16 Correct 11 ms 10200 KB Output is correct
17 Correct 12 ms 10200 KB Output is correct
18 Correct 13 ms 10200 KB Output is correct
19 Correct 11 ms 10200 KB Output is correct
20 Correct 13 ms 10200 KB Output is correct
21 Correct 13 ms 10200 KB Output is correct
22 Correct 13 ms 10200 KB Output is correct
23 Correct 13 ms 10200 KB Output is correct
24 Correct 10 ms 10324 KB Output is correct
25 Correct 14 ms 10324 KB Output is correct
26 Correct 14 ms 10324 KB Output is correct
27 Correct 14 ms 10324 KB Output is correct
28 Correct 15 ms 10324 KB Output is correct
29 Correct 12 ms 10324 KB Output is correct
30 Correct 15 ms 10324 KB Output is correct
31 Correct 10 ms 10324 KB Output is correct
32 Correct 12 ms 10324 KB Output is correct
33 Correct 13 ms 10324 KB Output is correct
34 Correct 13 ms 10324 KB Output is correct
35 Correct 11 ms 10324 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 17 ms 10324 KB Output is correct
38 Correct 13 ms 10324 KB Output is correct
39 Correct 11 ms 10324 KB Output is correct
40 Correct 11 ms 10324 KB Output is correct
41 Correct 12 ms 10324 KB Output is correct
42 Correct 13 ms 10324 KB Output is correct
43 Correct 14 ms 10324 KB Output is correct
44 Correct 13 ms 10324 KB Output is correct
45 Correct 12 ms 10324 KB Output is correct
46 Correct 11 ms 10324 KB Output is correct
47 Correct 12 ms 10324 KB Output is correct
48 Correct 12 ms 10324 KB Output is correct
49 Correct 10 ms 10324 KB Output is correct
50 Correct 13 ms 10324 KB Output is correct
51 Correct 11 ms 10324 KB Output is correct
52 Correct 11 ms 10324 KB Output is correct
53 Correct 13 ms 10324 KB Output is correct
54 Correct 11 ms 10324 KB Output is correct
55 Correct 11 ms 10324 KB Output is correct
56 Correct 13 ms 10324 KB Output is correct
57 Correct 11 ms 10324 KB Output is correct
58 Correct 13 ms 10324 KB Output is correct
59 Correct 11 ms 10324 KB Output is correct
60 Correct 14 ms 10324 KB Output is correct
61 Correct 12 ms 10324 KB Output is correct
62 Correct 13 ms 10324 KB Output is correct
63 Correct 13 ms 10324 KB Output is correct
64 Correct 12 ms 10324 KB Output is correct
65 Correct 13 ms 10324 KB Output is correct
66 Correct 11 ms 10324 KB Output is correct
67 Correct 10 ms 10324 KB Output is correct
68 Correct 12 ms 10324 KB Output is correct
69 Correct 12 ms 10324 KB Output is correct
70 Correct 13 ms 10324 KB Output is correct
71 Correct 17 ms 10324 KB Output is correct
72 Correct 10 ms 10324 KB Output is correct
73 Correct 10 ms 10324 KB Output is correct
74 Correct 12 ms 10324 KB Output is correct
75 Correct 13 ms 10324 KB Output is correct
76 Correct 11 ms 10324 KB Output is correct
77 Correct 13 ms 10324 KB Output is correct
78 Correct 11 ms 10324 KB Output is correct
79 Correct 11 ms 10324 KB Output is correct
80 Correct 11 ms 10324 KB Output is correct
81 Correct 13 ms 10324 KB Output is correct
82 Correct 12 ms 10324 KB Output is correct
83 Correct 13 ms 10324 KB Output is correct
84 Correct 11 ms 10324 KB Output is correct
85 Correct 11 ms 10324 KB Output is correct
86 Correct 12 ms 10324 KB Output is correct
87 Correct 18 ms 10324 KB Output is correct
88 Correct 12 ms 10324 KB Output is correct
89 Correct 13 ms 10324 KB Output is correct
90 Correct 14 ms 10324 KB Output is correct
91 Correct 11 ms 10324 KB Output is correct
92 Correct 14 ms 10324 KB Output is correct
93 Correct 13 ms 10324 KB Output is correct
94 Correct 14 ms 10324 KB Output is correct
95 Correct 11 ms 10324 KB Output is correct
96 Correct 12 ms 10324 KB Output is correct
97 Correct 12 ms 10324 KB Output is correct
98 Correct 13 ms 10324 KB Output is correct
99 Correct 150 ms 17940 KB Output is correct
100 Correct 15 ms 17940 KB Output is correct
101 Correct 35 ms 17940 KB Output is correct
102 Correct 79 ms 17940 KB Output is correct
103 Correct 151 ms 18444 KB Output is correct
104 Correct 87 ms 18444 KB Output is correct
105 Correct 166 ms 18444 KB Output is correct
106 Correct 19 ms 18444 KB Output is correct
107 Correct 14 ms 18444 KB Output is correct
108 Correct 158 ms 18972 KB Output is correct
109 Correct 123 ms 18972 KB Output is correct
110 Correct 124 ms 18972 KB Output is correct
111 Correct 13 ms 18972 KB Output is correct
112 Correct 13 ms 18972 KB Output is correct
113 Execution timed out 3094 ms 18972 KB Time limit exceeded
114 Halted 0 ms 0 KB -