# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63207 | 2018-08-01T05:56:43 Z | 김세빈(#1833) | Alternating Current (BOI18_alternating) | C++11 | 3000 ms | 18152 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 fff[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, 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[P[i].first].push_back(i); x = i; } } else Y[P[i].first].push_back(i); } ans[x] = 1; s = P[x].first, e = P[x].second; for(i=s; ; ){ for(int &t: X[i]){ if(P[t].first < P[t].second){ if(i <= e && e < P[t].second) e = P[t].second; } else{ if(i <= e) e = P[t].second; else if(e < P[t].second) e = P[t].second; } } for(int &t: Y[i]) y = t; if(i == e){ ans[y] = 1; e = P[y].second; } i ++; if(i > n) i -= n; if(i == s) break; } for(i=1; i<=m; i++){ if(ans[i] == 0){ if(P[i].first < P[i].second){ for(int j=P[i].first; j<P[i].second; j++) fff[j] = 1; } else{ for(int j=P[i].first; j<=n; j++) fff[j] = 1; for(int j=1; j<P[i].second; j++) fff[j] = 1; } } } for(i=1; i<=n; i++){ if(!fff[i]) die(); fff[i] = 0; } for(i=1; i<=m; i++){ if(ans[i] == 1){ if(P[i].first < P[i].second){ for(int j=P[i].first; j<P[i].second; j++) fff[j] = 1; } else{ for(int j=P[i].first; j<=n; j++) fff[j] = 1; for(int j=1; j<P[i].second; j++) fff[j] = 1; } } } for(i=1; i<=n; i++){ if(!fff[i]) die(); fff[i] = 0; } for(i=1; i<=m; i++) printf("%d", ans[i]); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9828 KB | Output is correct |
3 | Correct | 10 ms | 9880 KB | Output is correct |
4 | Correct | 13 ms | 9900 KB | Output is correct |
5 | Correct | 13 ms | 9940 KB | Output is correct |
6 | Correct | 10 ms | 9988 KB | Output is correct |
7 | Correct | 10 ms | 9988 KB | Output is correct |
8 | Correct | 11 ms | 10064 KB | Output is correct |
9 | Correct | 11 ms | 10064 KB | Output is correct |
10 | Correct | 11 ms | 10064 KB | Output is correct |
11 | Correct | 12 ms | 10092 KB | Output is correct |
12 | Correct | 10 ms | 10092 KB | Output is correct |
13 | Correct | 10 ms | 10092 KB | Output is correct |
14 | Correct | 10 ms | 10092 KB | Output is correct |
15 | Correct | 12 ms | 10092 KB | Output is correct |
16 | Correct | 13 ms | 10224 KB | Output is correct |
17 | Correct | 10 ms | 10224 KB | Output is correct |
18 | Correct | 10 ms | 10224 KB | Output is correct |
19 | Correct | 11 ms | 10224 KB | Output is correct |
20 | Correct | 12 ms | 10224 KB | Output is correct |
21 | Correct | 11 ms | 10224 KB | Output is correct |
22 | Correct | 12 ms | 10224 KB | Output is correct |
23 | Correct | 13 ms | 10236 KB | Output is correct |
24 | Correct | 11 ms | 10236 KB | Output is correct |
25 | Correct | 12 ms | 10236 KB | Output is correct |
26 | Correct | 13 ms | 10236 KB | Output is correct |
27 | Correct | 10 ms | 10236 KB | Output is correct |
28 | Correct | 12 ms | 10236 KB | Output is correct |
29 | Correct | 12 ms | 10236 KB | Output is correct |
30 | Correct | 11 ms | 10236 KB | Output is correct |
31 | Correct | 11 ms | 10236 KB | Output is correct |
32 | Correct | 11 ms | 10236 KB | Output is correct |
33 | Correct | 10 ms | 10236 KB | Output is correct |
34 | Correct | 12 ms | 10236 KB | Output is correct |
35 | Correct | 12 ms | 10236 KB | Output is correct |
36 | Correct | 12 ms | 10236 KB | Output is correct |
37 | Correct | 11 ms | 10236 KB | Output is correct |
38 | Correct | 13 ms | 10236 KB | Output is correct |
39 | Correct | 12 ms | 10236 KB | Output is correct |
40 | Correct | 13 ms | 10236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9828 KB | Output is correct |
3 | Correct | 10 ms | 9880 KB | Output is correct |
4 | Correct | 13 ms | 9900 KB | Output is correct |
5 | Correct | 13 ms | 9940 KB | Output is correct |
6 | Correct | 10 ms | 9988 KB | Output is correct |
7 | Correct | 10 ms | 9988 KB | Output is correct |
8 | Correct | 11 ms | 10064 KB | Output is correct |
9 | Correct | 11 ms | 10064 KB | Output is correct |
10 | Correct | 11 ms | 10064 KB | Output is correct |
11 | Correct | 12 ms | 10092 KB | Output is correct |
12 | Correct | 10 ms | 10092 KB | Output is correct |
13 | Correct | 10 ms | 10092 KB | Output is correct |
14 | Correct | 10 ms | 10092 KB | Output is correct |
15 | Correct | 12 ms | 10092 KB | Output is correct |
16 | Correct | 13 ms | 10224 KB | Output is correct |
17 | Correct | 10 ms | 10224 KB | Output is correct |
18 | Correct | 10 ms | 10224 KB | Output is correct |
19 | Correct | 11 ms | 10224 KB | Output is correct |
20 | Correct | 12 ms | 10224 KB | Output is correct |
21 | Correct | 11 ms | 10224 KB | Output is correct |
22 | Correct | 12 ms | 10224 KB | Output is correct |
23 | Correct | 13 ms | 10236 KB | Output is correct |
24 | Correct | 11 ms | 10236 KB | Output is correct |
25 | Correct | 12 ms | 10236 KB | Output is correct |
26 | Correct | 13 ms | 10236 KB | Output is correct |
27 | Correct | 10 ms | 10236 KB | Output is correct |
28 | Correct | 12 ms | 10236 KB | Output is correct |
29 | Correct | 12 ms | 10236 KB | Output is correct |
30 | Correct | 11 ms | 10236 KB | Output is correct |
31 | Correct | 11 ms | 10236 KB | Output is correct |
32 | Correct | 11 ms | 10236 KB | Output is correct |
33 | Correct | 10 ms | 10236 KB | Output is correct |
34 | Correct | 12 ms | 10236 KB | Output is correct |
35 | Correct | 12 ms | 10236 KB | Output is correct |
36 | Correct | 12 ms | 10236 KB | Output is correct |
37 | Correct | 11 ms | 10236 KB | Output is correct |
38 | Correct | 13 ms | 10236 KB | Output is correct |
39 | Correct | 12 ms | 10236 KB | Output is correct |
40 | Correct | 13 ms | 10236 KB | Output is correct |
41 | Correct | 12 ms | 10236 KB | Output is correct |
42 | Correct | 12 ms | 10236 KB | Output is correct |
43 | Correct | 11 ms | 10236 KB | Output is correct |
44 | Correct | 14 ms | 10236 KB | Output is correct |
45 | Correct | 15 ms | 10236 KB | Output is correct |
46 | Correct | 14 ms | 10236 KB | Output is correct |
47 | Correct | 12 ms | 10236 KB | Output is correct |
48 | Correct | 10 ms | 10236 KB | Output is correct |
49 | Correct | 10 ms | 10236 KB | Output is correct |
50 | Correct | 10 ms | 10236 KB | Output is correct |
51 | Correct | 12 ms | 10236 KB | Output is correct |
52 | Correct | 11 ms | 10236 KB | Output is correct |
53 | Correct | 12 ms | 10236 KB | Output is correct |
54 | Correct | 11 ms | 10236 KB | Output is correct |
55 | Correct | 11 ms | 10236 KB | Output is correct |
56 | Correct | 11 ms | 10236 KB | Output is correct |
57 | Correct | 13 ms | 10236 KB | Output is correct |
58 | Correct | 12 ms | 10236 KB | Output is correct |
59 | Correct | 13 ms | 10236 KB | Output is correct |
60 | Correct | 13 ms | 10236 KB | Output is correct |
61 | Correct | 12 ms | 10236 KB | Output is correct |
62 | Correct | 10 ms | 10236 KB | Output is correct |
63 | Correct | 10 ms | 10236 KB | Output is correct |
64 | Correct | 12 ms | 10236 KB | Output is correct |
65 | Correct | 12 ms | 10236 KB | Output is correct |
66 | Correct | 12 ms | 10236 KB | Output is correct |
67 | Correct | 12 ms | 10236 KB | Output is correct |
68 | Correct | 10 ms | 10236 KB | Output is correct |
69 | Correct | 13 ms | 10236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9828 KB | Output is correct |
3 | Correct | 10 ms | 9880 KB | Output is correct |
4 | Correct | 13 ms | 9900 KB | Output is correct |
5 | Correct | 13 ms | 9940 KB | Output is correct |
6 | Correct | 10 ms | 9988 KB | Output is correct |
7 | Correct | 10 ms | 9988 KB | Output is correct |
8 | Correct | 11 ms | 10064 KB | Output is correct |
9 | Correct | 11 ms | 10064 KB | Output is correct |
10 | Correct | 11 ms | 10064 KB | Output is correct |
11 | Correct | 12 ms | 10092 KB | Output is correct |
12 | Correct | 10 ms | 10092 KB | Output is correct |
13 | Correct | 10 ms | 10092 KB | Output is correct |
14 | Correct | 10 ms | 10092 KB | Output is correct |
15 | Correct | 12 ms | 10092 KB | Output is correct |
16 | Correct | 13 ms | 10224 KB | Output is correct |
17 | Correct | 10 ms | 10224 KB | Output is correct |
18 | Correct | 10 ms | 10224 KB | Output is correct |
19 | Correct | 11 ms | 10224 KB | Output is correct |
20 | Correct | 12 ms | 10224 KB | Output is correct |
21 | Correct | 11 ms | 10224 KB | Output is correct |
22 | Correct | 12 ms | 10224 KB | Output is correct |
23 | Correct | 13 ms | 10236 KB | Output is correct |
24 | Correct | 11 ms | 10236 KB | Output is correct |
25 | Correct | 12 ms | 10236 KB | Output is correct |
26 | Correct | 13 ms | 10236 KB | Output is correct |
27 | Correct | 10 ms | 10236 KB | Output is correct |
28 | Correct | 12 ms | 10236 KB | Output is correct |
29 | Correct | 12 ms | 10236 KB | Output is correct |
30 | Correct | 11 ms | 10236 KB | Output is correct |
31 | Correct | 11 ms | 10236 KB | Output is correct |
32 | Correct | 11 ms | 10236 KB | Output is correct |
33 | Correct | 10 ms | 10236 KB | Output is correct |
34 | Correct | 12 ms | 10236 KB | Output is correct |
35 | Correct | 12 ms | 10236 KB | Output is correct |
36 | Correct | 12 ms | 10236 KB | Output is correct |
37 | Correct | 11 ms | 10236 KB | Output is correct |
38 | Correct | 13 ms | 10236 KB | Output is correct |
39 | Correct | 12 ms | 10236 KB | Output is correct |
40 | Correct | 13 ms | 10236 KB | Output is correct |
41 | Correct | 12 ms | 10236 KB | Output is correct |
42 | Correct | 12 ms | 10236 KB | Output is correct |
43 | Correct | 11 ms | 10236 KB | Output is correct |
44 | Correct | 14 ms | 10236 KB | Output is correct |
45 | Correct | 15 ms | 10236 KB | Output is correct |
46 | Correct | 14 ms | 10236 KB | Output is correct |
47 | Correct | 12 ms | 10236 KB | Output is correct |
48 | Correct | 10 ms | 10236 KB | Output is correct |
49 | Correct | 10 ms | 10236 KB | Output is correct |
50 | Correct | 10 ms | 10236 KB | Output is correct |
51 | Correct | 12 ms | 10236 KB | Output is correct |
52 | Correct | 11 ms | 10236 KB | Output is correct |
53 | Correct | 12 ms | 10236 KB | Output is correct |
54 | Correct | 11 ms | 10236 KB | Output is correct |
55 | Correct | 11 ms | 10236 KB | Output is correct |
56 | Correct | 11 ms | 10236 KB | Output is correct |
57 | Correct | 13 ms | 10236 KB | Output is correct |
58 | Correct | 12 ms | 10236 KB | Output is correct |
59 | Correct | 13 ms | 10236 KB | Output is correct |
60 | Correct | 13 ms | 10236 KB | Output is correct |
61 | Correct | 12 ms | 10236 KB | Output is correct |
62 | Correct | 10 ms | 10236 KB | Output is correct |
63 | Correct | 10 ms | 10236 KB | Output is correct |
64 | Correct | 12 ms | 10236 KB | Output is correct |
65 | Correct | 12 ms | 10236 KB | Output is correct |
66 | Correct | 12 ms | 10236 KB | Output is correct |
67 | Correct | 12 ms | 10236 KB | Output is correct |
68 | Correct | 10 ms | 10236 KB | Output is correct |
69 | Correct | 13 ms | 10236 KB | Output is correct |
70 | Correct | 12 ms | 10236 KB | Output is correct |
71 | Correct | 13 ms | 10236 KB | Output is correct |
72 | Correct | 12 ms | 10236 KB | Output is correct |
73 | Correct | 11 ms | 10236 KB | Output is correct |
74 | Correct | 10 ms | 10236 KB | Output is correct |
75 | Correct | 11 ms | 10236 KB | Output is correct |
76 | Correct | 15 ms | 10236 KB | Output is correct |
77 | Correct | 13 ms | 10236 KB | Output is correct |
78 | Correct | 10 ms | 10236 KB | Output is correct |
79 | Correct | 14 ms | 10236 KB | Output is correct |
80 | Correct | 12 ms | 10236 KB | Output is correct |
81 | Incorrect | 13 ms | 10236 KB | 'impossible' claimed, but there is a solution |
82 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3037 ms | 18152 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 9720 KB | Output is correct |
2 | Correct | 10 ms | 9828 KB | Output is correct |
3 | Correct | 10 ms | 9880 KB | Output is correct |
4 | Correct | 13 ms | 9900 KB | Output is correct |
5 | Correct | 13 ms | 9940 KB | Output is correct |
6 | Correct | 10 ms | 9988 KB | Output is correct |
7 | Correct | 10 ms | 9988 KB | Output is correct |
8 | Correct | 11 ms | 10064 KB | Output is correct |
9 | Correct | 11 ms | 10064 KB | Output is correct |
10 | Correct | 11 ms | 10064 KB | Output is correct |
11 | Correct | 12 ms | 10092 KB | Output is correct |
12 | Correct | 10 ms | 10092 KB | Output is correct |
13 | Correct | 10 ms | 10092 KB | Output is correct |
14 | Correct | 10 ms | 10092 KB | Output is correct |
15 | Correct | 12 ms | 10092 KB | Output is correct |
16 | Correct | 13 ms | 10224 KB | Output is correct |
17 | Correct | 10 ms | 10224 KB | Output is correct |
18 | Correct | 10 ms | 10224 KB | Output is correct |
19 | Correct | 11 ms | 10224 KB | Output is correct |
20 | Correct | 12 ms | 10224 KB | Output is correct |
21 | Correct | 11 ms | 10224 KB | Output is correct |
22 | Correct | 12 ms | 10224 KB | Output is correct |
23 | Correct | 13 ms | 10236 KB | Output is correct |
24 | Correct | 11 ms | 10236 KB | Output is correct |
25 | Correct | 12 ms | 10236 KB | Output is correct |
26 | Correct | 13 ms | 10236 KB | Output is correct |
27 | Correct | 10 ms | 10236 KB | Output is correct |
28 | Correct | 12 ms | 10236 KB | Output is correct |
29 | Correct | 12 ms | 10236 KB | Output is correct |
30 | Correct | 11 ms | 10236 KB | Output is correct |
31 | Correct | 11 ms | 10236 KB | Output is correct |
32 | Correct | 11 ms | 10236 KB | Output is correct |
33 | Correct | 10 ms | 10236 KB | Output is correct |
34 | Correct | 12 ms | 10236 KB | Output is correct |
35 | Correct | 12 ms | 10236 KB | Output is correct |
36 | Correct | 12 ms | 10236 KB | Output is correct |
37 | Correct | 11 ms | 10236 KB | Output is correct |
38 | Correct | 13 ms | 10236 KB | Output is correct |
39 | Correct | 12 ms | 10236 KB | Output is correct |
40 | Correct | 13 ms | 10236 KB | Output is correct |
41 | Correct | 12 ms | 10236 KB | Output is correct |
42 | Correct | 12 ms | 10236 KB | Output is correct |
43 | Correct | 11 ms | 10236 KB | Output is correct |
44 | Correct | 14 ms | 10236 KB | Output is correct |
45 | Correct | 15 ms | 10236 KB | Output is correct |
46 | Correct | 14 ms | 10236 KB | Output is correct |
47 | Correct | 12 ms | 10236 KB | Output is correct |
48 | Correct | 10 ms | 10236 KB | Output is correct |
49 | Correct | 10 ms | 10236 KB | Output is correct |
50 | Correct | 10 ms | 10236 KB | Output is correct |
51 | Correct | 12 ms | 10236 KB | Output is correct |
52 | Correct | 11 ms | 10236 KB | Output is correct |
53 | Correct | 12 ms | 10236 KB | Output is correct |
54 | Correct | 11 ms | 10236 KB | Output is correct |
55 | Correct | 11 ms | 10236 KB | Output is correct |
56 | Correct | 11 ms | 10236 KB | Output is correct |
57 | Correct | 13 ms | 10236 KB | Output is correct |
58 | Correct | 12 ms | 10236 KB | Output is correct |
59 | Correct | 13 ms | 10236 KB | Output is correct |
60 | Correct | 13 ms | 10236 KB | Output is correct |
61 | Correct | 12 ms | 10236 KB | Output is correct |
62 | Correct | 10 ms | 10236 KB | Output is correct |
63 | Correct | 10 ms | 10236 KB | Output is correct |
64 | Correct | 12 ms | 10236 KB | Output is correct |
65 | Correct | 12 ms | 10236 KB | Output is correct |
66 | Correct | 12 ms | 10236 KB | Output is correct |
67 | Correct | 12 ms | 10236 KB | Output is correct |
68 | Correct | 10 ms | 10236 KB | Output is correct |
69 | Correct | 13 ms | 10236 KB | Output is correct |
70 | Correct | 12 ms | 10236 KB | Output is correct |
71 | Correct | 13 ms | 10236 KB | Output is correct |
72 | Correct | 12 ms | 10236 KB | Output is correct |
73 | Correct | 11 ms | 10236 KB | Output is correct |
74 | Correct | 10 ms | 10236 KB | Output is correct |
75 | Correct | 11 ms | 10236 KB | Output is correct |
76 | Correct | 15 ms | 10236 KB | Output is correct |
77 | Correct | 13 ms | 10236 KB | Output is correct |
78 | Correct | 10 ms | 10236 KB | Output is correct |
79 | Correct | 14 ms | 10236 KB | Output is correct |
80 | Correct | 12 ms | 10236 KB | Output is correct |
81 | Incorrect | 13 ms | 10236 KB | 'impossible' claimed, but there is a solution |
82 | Halted | 0 ms | 0 KB | - |