답안 #1066673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066673 2024-08-20T04:42:01 Z thinknoexit Alternating Current (BOI18_alternating) C++17
74 / 100
95 ms 19280 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
vector<int> v[N];
bool in[N];
vector<int> adj[N];
int col[N];
bool bipartite(int v, int c = 1) {
    if (col[v]) return col[v] == c;
    col[v] = c;
    for (auto& x : adj[v]) {
        if (!bipartite(x, 3 - c)) return false;
    }
    return true;
}
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    set<int> s;
    for (int i = 0;i < n;i++) s.insert(i);
    for (int i = 0;i < m;i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        vector<int> rem;
        if (l <= r) {
            auto x = s.lower_bound(l);
            auto y = s.upper_bound(r);
            for (;x != y;x++) {
                v[*x].push_back(i);
                if ((int)v[*x].size() == 3) rem.push_back(*x);
            }
        }
        else {
            auto x = s.lower_bound(l);
            for (;x != s.end();x++) {
                v[*x].push_back(i);
                if ((int)v[*x].size() == 3) rem.push_back(*x);
            }
            x = s.begin();
            auto y = s.upper_bound(r);
            for (;x != y;x++) {
                v[*x].push_back(i);
                if ((int)v[*x].size() == 3) rem.push_back(*x);
            }
        }
        for (auto& x : rem) s.erase(x);
    }
    for (int i = 0;i < n;i++) {
        if ((int)v[i].size() <= 1) {
            cout << "impossible\n";
            return 0;
        }
    }
    for (int i = 0;i < n;i++) {
        if ((int)v[i].size() == 2) {
            in[v[i][0]] = in[v[i][1]] = 1;
            adj[v[i][0]].push_back(v[i][1]);
            adj[v[i][1]].push_back(v[i][0]);
        }
    }
    for (int i = 0;i < m;i++) {
        if (in[i] && !col[i]) {
            if (!bipartite(i)) {
                cout << "impossible\n";
                return 0;
            }
        }
    }
    for (int i = 0;i < m;i++) col[i]--;
    for (int i = 0;i < n;i++) {
        int bit = 0;
        for (auto& x : v[i]) {
            if (col[x] != -1) bit |= (1 << col[x]);
        }
        if (bit == 3) continue;
        if (!(bit & 1)) {
            for (auto& x : v[i]) {
                if (col[x] != -1) continue;
                col[x] = 0;
                break;
            }
        }
        if (!(bit & 2)) {
            for (auto& x : v[i]) {
                if (col[x] != -1) continue;
                col[x] = 1;
                break;
            }
        }
    }
    for (int i = 0;i < m;i++) {
        if (col[i] == -1) col[i] = 0;
        cout << col[i];
    }
    cout << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4916 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5168 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 5208 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4916 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5168 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 5208 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 5152 KB Output is correct
49 Correct 2 ms 4952 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 2 ms 5164 KB Output is correct
58 Correct 2 ms 4952 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Correct 2 ms 4956 KB Output is correct
62 Correct 2 ms 4956 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5168 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 3 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4916 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5168 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 5208 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 5152 KB Output is correct
49 Correct 2 ms 4952 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 2 ms 5164 KB Output is correct
58 Correct 2 ms 4952 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Correct 2 ms 4956 KB Output is correct
62 Correct 2 ms 4956 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5168 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 3 ms 4952 KB Output is correct
70 Correct 2 ms 5208 KB Output is correct
71 Correct 2 ms 5212 KB Output is correct
72 Correct 2 ms 5208 KB Output is correct
73 Correct 2 ms 5208 KB Output is correct
74 Correct 2 ms 5212 KB Output is correct
75 Correct 2 ms 4952 KB Output is correct
76 Correct 2 ms 5208 KB Output is correct
77 Correct 3 ms 5212 KB Output is correct
78 Correct 3 ms 5212 KB Output is correct
79 Correct 2 ms 5212 KB Output is correct
80 Correct 4 ms 5212 KB Output is correct
81 Correct 3 ms 5248 KB Output is correct
82 Correct 3 ms 5212 KB Output is correct
83 Correct 2 ms 5164 KB Output is correct
84 Correct 2 ms 5212 KB Output is correct
85 Correct 2 ms 5252 KB Output is correct
86 Correct 2 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 2 ms 5464 KB Output is correct
89 Correct 3 ms 5212 KB Output is correct
90 Correct 2 ms 5212 KB Output is correct
91 Correct 2 ms 5212 KB Output is correct
92 Correct 2 ms 4952 KB Output is correct
93 Correct 2 ms 5212 KB Output is correct
94 Correct 2 ms 5212 KB Output is correct
95 Correct 2 ms 5212 KB Output is correct
96 Correct 3 ms 5212 KB Output is correct
97 Correct 2 ms 5212 KB Output is correct
98 Correct 2 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 14264 KB Output is correct
2 Correct 27 ms 13776 KB Output is correct
3 Correct 38 ms 13708 KB Output is correct
4 Correct 42 ms 13900 KB Output is correct
5 Correct 95 ms 17536 KB Output is correct
6 Correct 94 ms 13044 KB Output is correct
7 Correct 88 ms 17492 KB Output is correct
8 Correct 35 ms 12372 KB Output is correct
9 Correct 28 ms 11856 KB Output is correct
10 Correct 94 ms 17744 KB Output is correct
11 Correct 87 ms 16884 KB Output is correct
12 Correct 79 ms 17616 KB Output is correct
13 Correct 24 ms 12884 KB Output is correct
14 Correct 26 ms 12884 KB Output is correct
15 Correct 92 ms 14420 KB Output is correct
16 Correct 37 ms 12044 KB Output is correct
17 Correct 56 ms 13568 KB Output is correct
18 Correct 16 ms 7004 KB Output is correct
19 Correct 33 ms 11988 KB Output is correct
20 Correct 40 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4916 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5168 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 5208 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 5152 KB Output is correct
49 Correct 2 ms 4952 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 2 ms 5164 KB Output is correct
58 Correct 2 ms 4952 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Correct 2 ms 4956 KB Output is correct
62 Correct 2 ms 4956 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5168 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 3 ms 4952 KB Output is correct
70 Correct 2 ms 5208 KB Output is correct
71 Correct 2 ms 5212 KB Output is correct
72 Correct 2 ms 5208 KB Output is correct
73 Correct 2 ms 5208 KB Output is correct
74 Correct 2 ms 5212 KB Output is correct
75 Correct 2 ms 4952 KB Output is correct
76 Correct 2 ms 5208 KB Output is correct
77 Correct 3 ms 5212 KB Output is correct
78 Correct 3 ms 5212 KB Output is correct
79 Correct 2 ms 5212 KB Output is correct
80 Correct 4 ms 5212 KB Output is correct
81 Correct 3 ms 5248 KB Output is correct
82 Correct 3 ms 5212 KB Output is correct
83 Correct 2 ms 5164 KB Output is correct
84 Correct 2 ms 5212 KB Output is correct
85 Correct 2 ms 5252 KB Output is correct
86 Correct 2 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 2 ms 5464 KB Output is correct
89 Correct 3 ms 5212 KB Output is correct
90 Correct 2 ms 5212 KB Output is correct
91 Correct 2 ms 5212 KB Output is correct
92 Correct 2 ms 4952 KB Output is correct
93 Correct 2 ms 5212 KB Output is correct
94 Correct 2 ms 5212 KB Output is correct
95 Correct 2 ms 5212 KB Output is correct
96 Correct 3 ms 5212 KB Output is correct
97 Correct 2 ms 5212 KB Output is correct
98 Correct 2 ms 5208 KB Output is correct
99 Correct 45 ms 14264 KB Output is correct
100 Correct 27 ms 13776 KB Output is correct
101 Correct 38 ms 13708 KB Output is correct
102 Correct 42 ms 13900 KB Output is correct
103 Correct 95 ms 17536 KB Output is correct
104 Correct 94 ms 13044 KB Output is correct
105 Correct 88 ms 17492 KB Output is correct
106 Correct 35 ms 12372 KB Output is correct
107 Correct 28 ms 11856 KB Output is correct
108 Correct 94 ms 17744 KB Output is correct
109 Correct 87 ms 16884 KB Output is correct
110 Correct 79 ms 17616 KB Output is correct
111 Correct 24 ms 12884 KB Output is correct
112 Correct 26 ms 12884 KB Output is correct
113 Correct 92 ms 14420 KB Output is correct
114 Correct 37 ms 12044 KB Output is correct
115 Correct 56 ms 13568 KB Output is correct
116 Correct 16 ms 7004 KB Output is correct
117 Correct 33 ms 11988 KB Output is correct
118 Correct 40 ms 13908 KB Output is correct
119 Correct 30 ms 13876 KB Output is correct
120 Correct 79 ms 19280 KB Output is correct
121 Correct 61 ms 15968 KB Output is correct
122 Correct 2 ms 4956 KB Output is correct
123 Correct 25 ms 12832 KB Output is correct
124 Correct 50 ms 12624 KB Output is correct
125 Incorrect 53 ms 13392 KB no wires in direction 0 between segments 62295 and 62295
126 Halted 0 ms 0 KB -