답안 #1066696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066696 2024-08-20T05:00:04 Z thinknoexit Alternating Current (BOI18_alternating) C++17
100 / 100
103 ms 20208 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
int n, m;
struct A {
    int l, r, idx;
    bool operator < (const A& o) const {
        int sza = r - l;
        if (l > r) sza += n;
        int szb = o.r - o.l;
        if (o.l > o.r) szb += n;
        return sza > szb;
    }
} inter[N];
vector<int> v[N];
bool in[N];
vector<int> adj[N];
int col[N], ans[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);
    cin >> n >> m;
    set<int> s;
    for (int i = 0;i < n;i++) s.insert(i);
    for (int i = 0;i < m;i++) {
        cin >> inter[i].l >> inter[i].r;
        inter[i].l--, inter[i].r--;
        inter[i].idx = i;
    }
    sort(inter, inter + m);
    for (int i = 0;i < m;i++) {
        int l = inter[i].l, r = inter[i].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;
        ans[inter[i].idx] = col[i];
    }
    for (int i = 0;i < m;i++) cout << ans[i];
    cout << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 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 3 ms 4956 KB Output is correct
10 Correct 2 ms 5180 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 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 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 4956 KB Output is correct
23 Correct 2 ms 4956 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 4952 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 4952 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 4952 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 5168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 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 3 ms 4956 KB Output is correct
10 Correct 2 ms 5180 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 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 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 4956 KB Output is correct
23 Correct 2 ms 4956 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 4952 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 4952 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 4952 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 5168 KB Output is correct
41 Correct 2 ms 4952 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 5156 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4984 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 3 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 4952 KB Output is correct
57 Correct 2 ms 4952 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 4956 KB Output is correct
61 Correct 3 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 5208 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4952 KB Output is correct
67 Correct 3 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 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 3 ms 4956 KB Output is correct
10 Correct 2 ms 5180 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 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 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 4956 KB Output is correct
23 Correct 2 ms 4956 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 4952 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 4952 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 4952 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 5168 KB Output is correct
41 Correct 2 ms 4952 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 5156 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4984 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 3 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 4952 KB Output is correct
57 Correct 2 ms 4952 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 4956 KB Output is correct
61 Correct 3 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 5208 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4952 KB Output is correct
67 Correct 3 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 5212 KB Output is correct
71 Correct 2 ms 5212 KB Output is correct
72 Correct 2 ms 5212 KB Output is correct
73 Correct 2 ms 5212 KB Output is correct
74 Correct 3 ms 5212 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 2 ms 5212 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 2 ms 5260 KB Output is correct
80 Correct 2 ms 5212 KB Output is correct
81 Correct 2 ms 5212 KB Output is correct
82 Correct 2 ms 5212 KB Output is correct
83 Correct 3 ms 5208 KB Output is correct
84 Correct 3 ms 5212 KB Output is correct
85 Correct 2 ms 5028 KB Output is correct
86 Correct 2 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 3 ms 5212 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 5180 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 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 15124 KB Output is correct
2 Correct 28 ms 13772 KB Output is correct
3 Correct 39 ms 14756 KB Output is correct
4 Correct 42 ms 14808 KB Output is correct
5 Correct 92 ms 19028 KB Output is correct
6 Correct 94 ms 13908 KB Output is correct
7 Correct 91 ms 18768 KB Output is correct
8 Correct 31 ms 12632 KB Output is correct
9 Correct 32 ms 12636 KB Output is correct
10 Correct 93 ms 19288 KB Output is correct
11 Correct 79 ms 17856 KB Output is correct
12 Correct 96 ms 19040 KB Output is correct
13 Correct 25 ms 12948 KB Output is correct
14 Correct 25 ms 12756 KB Output is correct
15 Correct 86 ms 16068 KB Output is correct
16 Correct 38 ms 13660 KB Output is correct
17 Correct 52 ms 16272 KB Output is correct
18 Correct 27 ms 8512 KB Output is correct
19 Correct 39 ms 13528 KB Output is correct
20 Correct 70 ms 15444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 4952 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 3 ms 4956 KB Output is correct
10 Correct 2 ms 5180 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 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 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 4956 KB Output is correct
23 Correct 2 ms 4956 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 4952 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 4952 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 4952 KB Output is correct
38 Correct 2 ms 4952 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 5168 KB Output is correct
41 Correct 2 ms 4952 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 5156 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4984 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 3 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 4952 KB Output is correct
57 Correct 2 ms 4952 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 4956 KB Output is correct
61 Correct 3 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 5208 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4952 KB Output is correct
67 Correct 3 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 5212 KB Output is correct
71 Correct 2 ms 5212 KB Output is correct
72 Correct 2 ms 5212 KB Output is correct
73 Correct 2 ms 5212 KB Output is correct
74 Correct 3 ms 5212 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 2 ms 5212 KB Output is correct
78 Correct 2 ms 5212 KB Output is correct
79 Correct 2 ms 5260 KB Output is correct
80 Correct 2 ms 5212 KB Output is correct
81 Correct 2 ms 5212 KB Output is correct
82 Correct 2 ms 5212 KB Output is correct
83 Correct 3 ms 5208 KB Output is correct
84 Correct 3 ms 5212 KB Output is correct
85 Correct 2 ms 5028 KB Output is correct
86 Correct 2 ms 5212 KB Output is correct
87 Correct 2 ms 5212 KB Output is correct
88 Correct 3 ms 5212 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 5180 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 5212 KB Output is correct
99 Correct 45 ms 15124 KB Output is correct
100 Correct 28 ms 13772 KB Output is correct
101 Correct 39 ms 14756 KB Output is correct
102 Correct 42 ms 14808 KB Output is correct
103 Correct 92 ms 19028 KB Output is correct
104 Correct 94 ms 13908 KB Output is correct
105 Correct 91 ms 18768 KB Output is correct
106 Correct 31 ms 12632 KB Output is correct
107 Correct 32 ms 12636 KB Output is correct
108 Correct 93 ms 19288 KB Output is correct
109 Correct 79 ms 17856 KB Output is correct
110 Correct 96 ms 19040 KB Output is correct
111 Correct 25 ms 12948 KB Output is correct
112 Correct 25 ms 12756 KB Output is correct
113 Correct 86 ms 16068 KB Output is correct
114 Correct 38 ms 13660 KB Output is correct
115 Correct 52 ms 16272 KB Output is correct
116 Correct 27 ms 8512 KB Output is correct
117 Correct 39 ms 13528 KB Output is correct
118 Correct 70 ms 15444 KB Output is correct
119 Correct 27 ms 13916 KB Output is correct
120 Correct 90 ms 20208 KB Output is correct
121 Correct 65 ms 16708 KB Output is correct
122 Correct 2 ms 4956 KB Output is correct
123 Correct 28 ms 13080 KB Output is correct
124 Correct 52 ms 13404 KB Output is correct
125 Correct 59 ms 13912 KB Output is correct
126 Correct 33 ms 13140 KB Output is correct
127 Correct 43 ms 12884 KB Output is correct
128 Correct 103 ms 18128 KB Output is correct
129 Correct 73 ms 16472 KB Output is correct
130 Correct 91 ms 16876 KB Output is correct
131 Correct 31 ms 13820 KB Output is correct
132 Correct 32 ms 14080 KB Output is correct
133 Correct 65 ms 16316 KB Output is correct
134 Correct 50 ms 14156 KB Output is correct
135 Correct 35 ms 13296 KB Output is correct
136 Correct 69 ms 12944 KB Output is correct
137 Correct 63 ms 13164 KB Output is correct
138 Correct 38 ms 11592 KB Output is correct