Submission #1066675

# Submission time Handle Problem Language Result Execution time Memory
1066675 2024-08-20T04:45:18 Z thinknoexit Alternating Current (BOI18_alternating) C++17
74 / 100
98 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] = 1;
        cout << col[i];
    }
    cout << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 5168 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4952 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 5064 KB Output is correct
10 Correct 2 ms 4956 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 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5160 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 3 ms 5164 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 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 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 5160 KB Output is correct
39 Correct 3 ms 4956 KB Output is correct
40 Correct 3 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 5168 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4952 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 5064 KB Output is correct
10 Correct 2 ms 4956 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 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5160 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 3 ms 5164 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 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 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 5160 KB Output is correct
39 Correct 3 ms 4956 KB Output is correct
40 Correct 3 ms 5036 KB Output is correct
41 Correct 3 ms 5160 KB Output is correct
42 Correct 3 ms 4956 KB Output is correct
43 Correct 3 ms 4956 KB Output is correct
44 Correct 2 ms 4968 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 2 ms 5164 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 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 4952 KB Output is correct
54 Correct 2 ms 4952 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 3 ms 5088 KB Output is correct
57 Correct 2 ms 4956 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4952 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 4952 KB Output is correct
64 Correct 2 ms 5168 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5172 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 4 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 5168 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4952 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 5064 KB Output is correct
10 Correct 2 ms 4956 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 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5160 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 3 ms 5164 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 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 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 5160 KB Output is correct
39 Correct 3 ms 4956 KB Output is correct
40 Correct 3 ms 5036 KB Output is correct
41 Correct 3 ms 5160 KB Output is correct
42 Correct 3 ms 4956 KB Output is correct
43 Correct 3 ms 4956 KB Output is correct
44 Correct 2 ms 4968 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 2 ms 5164 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 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 4952 KB Output is correct
54 Correct 2 ms 4952 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 3 ms 5088 KB Output is correct
57 Correct 2 ms 4956 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4952 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 4952 KB Output is correct
64 Correct 2 ms 5168 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5172 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 4 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 5208 KB Output is correct
71 Correct 4 ms 5216 KB Output is correct
72 Correct 2 ms 5212 KB Output is correct
73 Correct 3 ms 5212 KB Output is correct
74 Correct 2 ms 5060 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 3 ms 5208 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 2 ms 5212 KB Output is correct
80 Correct 3 ms 5168 KB Output is correct
81 Correct 3 ms 5212 KB Output is correct
82 Correct 2 ms 5236 KB Output is correct
83 Correct 2 ms 5212 KB Output is correct
84 Correct 2 ms 5060 KB Output is correct
85 Correct 2 ms 5160 KB Output is correct
86 Correct 3 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 2 ms 5212 KB Output is correct
89 Correct 3 ms 5208 KB Output is correct
90 Correct 2 ms 5208 KB Output is correct
91 Correct 3 ms 5212 KB Output is correct
92 Correct 2 ms 4956 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 2 ms 5212 KB Output is correct
97 Correct 2 ms 5212 KB Output is correct
98 Correct 2 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 14424 KB Output is correct
2 Correct 26 ms 13772 KB Output is correct
3 Correct 39 ms 13640 KB Output is correct
4 Correct 38 ms 13696 KB Output is correct
5 Correct 91 ms 17612 KB Output is correct
6 Correct 87 ms 12720 KB Output is correct
7 Correct 88 ms 17492 KB Output is correct
8 Correct 34 ms 12380 KB Output is correct
9 Correct 29 ms 12024 KB Output is correct
10 Correct 98 ms 17748 KB Output is correct
11 Correct 76 ms 16724 KB Output is correct
12 Correct 88 ms 17608 KB Output is correct
13 Correct 27 ms 12880 KB Output is correct
14 Correct 23 ms 12884 KB Output is correct
15 Correct 91 ms 14424 KB Output is correct
16 Correct 36 ms 12040 KB Output is correct
17 Correct 49 ms 13592 KB Output is correct
18 Correct 16 ms 7000 KB Output is correct
19 Correct 37 ms 11860 KB Output is correct
20 Correct 39 ms 13784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 5168 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4952 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 5064 KB Output is correct
10 Correct 2 ms 4956 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 4956 KB Output is correct
16 Correct 3 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 5160 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 3 ms 5164 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 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 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 5160 KB Output is correct
39 Correct 3 ms 4956 KB Output is correct
40 Correct 3 ms 5036 KB Output is correct
41 Correct 3 ms 5160 KB Output is correct
42 Correct 3 ms 4956 KB Output is correct
43 Correct 3 ms 4956 KB Output is correct
44 Correct 2 ms 4968 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 2 ms 5164 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 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 4952 KB Output is correct
54 Correct 2 ms 4952 KB Output is correct
55 Correct 2 ms 4956 KB Output is correct
56 Correct 3 ms 5088 KB Output is correct
57 Correct 2 ms 4956 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4952 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 4952 KB Output is correct
64 Correct 2 ms 5168 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 5172 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 4 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 5208 KB Output is correct
71 Correct 4 ms 5216 KB Output is correct
72 Correct 2 ms 5212 KB Output is correct
73 Correct 3 ms 5212 KB Output is correct
74 Correct 2 ms 5060 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 3 ms 5208 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 2 ms 5212 KB Output is correct
80 Correct 3 ms 5168 KB Output is correct
81 Correct 3 ms 5212 KB Output is correct
82 Correct 2 ms 5236 KB Output is correct
83 Correct 2 ms 5212 KB Output is correct
84 Correct 2 ms 5060 KB Output is correct
85 Correct 2 ms 5160 KB Output is correct
86 Correct 3 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 2 ms 5212 KB Output is correct
89 Correct 3 ms 5208 KB Output is correct
90 Correct 2 ms 5208 KB Output is correct
91 Correct 3 ms 5212 KB Output is correct
92 Correct 2 ms 4956 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 2 ms 5212 KB Output is correct
97 Correct 2 ms 5212 KB Output is correct
98 Correct 2 ms 5032 KB Output is correct
99 Correct 49 ms 14424 KB Output is correct
100 Correct 26 ms 13772 KB Output is correct
101 Correct 39 ms 13640 KB Output is correct
102 Correct 38 ms 13696 KB Output is correct
103 Correct 91 ms 17612 KB Output is correct
104 Correct 87 ms 12720 KB Output is correct
105 Correct 88 ms 17492 KB Output is correct
106 Correct 34 ms 12380 KB Output is correct
107 Correct 29 ms 12024 KB Output is correct
108 Correct 98 ms 17748 KB Output is correct
109 Correct 76 ms 16724 KB Output is correct
110 Correct 88 ms 17608 KB Output is correct
111 Correct 27 ms 12880 KB Output is correct
112 Correct 23 ms 12884 KB Output is correct
113 Correct 91 ms 14424 KB Output is correct
114 Correct 36 ms 12040 KB Output is correct
115 Correct 49 ms 13592 KB Output is correct
116 Correct 16 ms 7000 KB Output is correct
117 Correct 37 ms 11860 KB Output is correct
118 Correct 39 ms 13784 KB Output is correct
119 Correct 25 ms 13652 KB Output is correct
120 Correct 86 ms 19280 KB Output is correct
121 Correct 65 ms 15972 KB Output is correct
122 Correct 3 ms 4956 KB Output is correct
123 Correct 28 ms 12796 KB Output is correct
124 Correct 50 ms 12636 KB Output is correct
125 Incorrect 51 ms 13536 KB no wires in direction 0 between segments 62295 and 62295
126 Halted 0 ms 0 KB -