Submission #397573

# Submission time Handle Problem Language Result Execution time Memory
397573 2021-05-02T12:13:10 Z timmyfeng Rope (JOI17_rope) C++17
55 / 100
2500 ms 100264 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000001;

int color[N], tally[N], ans[N];
map<int, int> pairs[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        cin >> color[i];
        ++tally[color[i]];
    }

    multiset<int> maxi = {0};
    for (int i = 1; i <= m; ++i) {
        maxi.insert(tally[i]);
        ans[i] = INT_MAX;
    }

    for (int k = 0; k < 2; ++k) {
        fill(pairs, pairs + m + 1, map<int, int>());

        for (int i = k; i + 2 <= n; i += 2) {
            if (color[i] != color[i + 1]) {
                ++pairs[color[i]][color[i + 1]];
                ++pairs[color[i + 1]][color[i]];
            }
        }

        for (int i = 1; i <= m; ++i) {
            maxi.erase(maxi.find(tally[i]));

            for (auto [j, k] : pairs[i]) {
                maxi.erase(maxi.find(tally[j]));
                maxi.insert(tally[j] - k);
            }

            ans[i] = min(ans[i], n - tally[i] - *(--maxi.end()));

            for (auto [j, k] : pairs[i]) {
                maxi.erase(maxi.find(tally[j] - k));
                maxi.insert(tally[j]);
            }

            maxi.insert(tally[i]);
        }
    }

    for (int i = 1; i <= m; ++i) {
        cout << ans[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47204 KB Output is correct
2 Correct 28 ms 47200 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47308 KB Output is correct
5 Correct 29 ms 47276 KB Output is correct
6 Correct 29 ms 47212 KB Output is correct
7 Correct 28 ms 47264 KB Output is correct
8 Correct 28 ms 47292 KB Output is correct
9 Correct 28 ms 47292 KB Output is correct
10 Correct 28 ms 47308 KB Output is correct
11 Correct 27 ms 47180 KB Output is correct
12 Correct 27 ms 47212 KB Output is correct
13 Correct 28 ms 47192 KB Output is correct
14 Correct 29 ms 47208 KB Output is correct
15 Correct 29 ms 47236 KB Output is correct
16 Correct 28 ms 47252 KB Output is correct
17 Correct 28 ms 47308 KB Output is correct
18 Correct 27 ms 47308 KB Output is correct
19 Correct 28 ms 47180 KB Output is correct
20 Correct 29 ms 47296 KB Output is correct
21 Correct 28 ms 47308 KB Output is correct
22 Correct 27 ms 47300 KB Output is correct
23 Correct 28 ms 47272 KB Output is correct
24 Correct 28 ms 47196 KB Output is correct
25 Correct 29 ms 47196 KB Output is correct
26 Correct 29 ms 47232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47204 KB Output is correct
2 Correct 28 ms 47200 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47308 KB Output is correct
5 Correct 29 ms 47276 KB Output is correct
6 Correct 29 ms 47212 KB Output is correct
7 Correct 28 ms 47264 KB Output is correct
8 Correct 28 ms 47292 KB Output is correct
9 Correct 28 ms 47292 KB Output is correct
10 Correct 28 ms 47308 KB Output is correct
11 Correct 27 ms 47180 KB Output is correct
12 Correct 27 ms 47212 KB Output is correct
13 Correct 28 ms 47192 KB Output is correct
14 Correct 29 ms 47208 KB Output is correct
15 Correct 29 ms 47236 KB Output is correct
16 Correct 28 ms 47252 KB Output is correct
17 Correct 28 ms 47308 KB Output is correct
18 Correct 27 ms 47308 KB Output is correct
19 Correct 28 ms 47180 KB Output is correct
20 Correct 29 ms 47296 KB Output is correct
21 Correct 28 ms 47308 KB Output is correct
22 Correct 27 ms 47300 KB Output is correct
23 Correct 28 ms 47272 KB Output is correct
24 Correct 28 ms 47196 KB Output is correct
25 Correct 29 ms 47196 KB Output is correct
26 Correct 29 ms 47232 KB Output is correct
27 Correct 39 ms 47872 KB Output is correct
28 Correct 36 ms 47896 KB Output is correct
29 Correct 40 ms 47820 KB Output is correct
30 Correct 42 ms 47808 KB Output is correct
31 Correct 40 ms 47812 KB Output is correct
32 Correct 37 ms 47844 KB Output is correct
33 Correct 39 ms 47876 KB Output is correct
34 Correct 39 ms 47876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47204 KB Output is correct
2 Correct 28 ms 47200 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47308 KB Output is correct
5 Correct 29 ms 47276 KB Output is correct
6 Correct 29 ms 47212 KB Output is correct
7 Correct 28 ms 47264 KB Output is correct
8 Correct 28 ms 47292 KB Output is correct
9 Correct 28 ms 47292 KB Output is correct
10 Correct 28 ms 47308 KB Output is correct
11 Correct 27 ms 47180 KB Output is correct
12 Correct 27 ms 47212 KB Output is correct
13 Correct 28 ms 47192 KB Output is correct
14 Correct 29 ms 47208 KB Output is correct
15 Correct 29 ms 47236 KB Output is correct
16 Correct 28 ms 47252 KB Output is correct
17 Correct 28 ms 47308 KB Output is correct
18 Correct 27 ms 47308 KB Output is correct
19 Correct 28 ms 47180 KB Output is correct
20 Correct 29 ms 47296 KB Output is correct
21 Correct 28 ms 47308 KB Output is correct
22 Correct 27 ms 47300 KB Output is correct
23 Correct 28 ms 47272 KB Output is correct
24 Correct 28 ms 47196 KB Output is correct
25 Correct 29 ms 47196 KB Output is correct
26 Correct 29 ms 47232 KB Output is correct
27 Correct 39 ms 47872 KB Output is correct
28 Correct 36 ms 47896 KB Output is correct
29 Correct 40 ms 47820 KB Output is correct
30 Correct 42 ms 47808 KB Output is correct
31 Correct 40 ms 47812 KB Output is correct
32 Correct 37 ms 47844 KB Output is correct
33 Correct 39 ms 47876 KB Output is correct
34 Correct 39 ms 47876 KB Output is correct
35 Correct 159 ms 52000 KB Output is correct
36 Correct 171 ms 51908 KB Output is correct
37 Correct 165 ms 51888 KB Output is correct
38 Correct 156 ms 52036 KB Output is correct
39 Correct 157 ms 51824 KB Output is correct
40 Correct 96 ms 50244 KB Output is correct
41 Correct 95 ms 50132 KB Output is correct
42 Correct 82 ms 49604 KB Output is correct
43 Correct 83 ms 49568 KB Output is correct
44 Correct 97 ms 50124 KB Output is correct
45 Correct 98 ms 50040 KB Output is correct
46 Correct 84 ms 49620 KB Output is correct
47 Correct 83 ms 49492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47204 KB Output is correct
2 Correct 28 ms 47200 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47308 KB Output is correct
5 Correct 29 ms 47276 KB Output is correct
6 Correct 29 ms 47212 KB Output is correct
7 Correct 28 ms 47264 KB Output is correct
8 Correct 28 ms 47292 KB Output is correct
9 Correct 28 ms 47292 KB Output is correct
10 Correct 28 ms 47308 KB Output is correct
11 Correct 27 ms 47180 KB Output is correct
12 Correct 27 ms 47212 KB Output is correct
13 Correct 28 ms 47192 KB Output is correct
14 Correct 29 ms 47208 KB Output is correct
15 Correct 29 ms 47236 KB Output is correct
16 Correct 28 ms 47252 KB Output is correct
17 Correct 28 ms 47308 KB Output is correct
18 Correct 27 ms 47308 KB Output is correct
19 Correct 28 ms 47180 KB Output is correct
20 Correct 29 ms 47296 KB Output is correct
21 Correct 28 ms 47308 KB Output is correct
22 Correct 27 ms 47300 KB Output is correct
23 Correct 28 ms 47272 KB Output is correct
24 Correct 28 ms 47196 KB Output is correct
25 Correct 29 ms 47196 KB Output is correct
26 Correct 29 ms 47232 KB Output is correct
27 Correct 39 ms 47872 KB Output is correct
28 Correct 36 ms 47896 KB Output is correct
29 Correct 40 ms 47820 KB Output is correct
30 Correct 42 ms 47808 KB Output is correct
31 Correct 40 ms 47812 KB Output is correct
32 Correct 37 ms 47844 KB Output is correct
33 Correct 39 ms 47876 KB Output is correct
34 Correct 39 ms 47876 KB Output is correct
35 Correct 159 ms 52000 KB Output is correct
36 Correct 171 ms 51908 KB Output is correct
37 Correct 165 ms 51888 KB Output is correct
38 Correct 156 ms 52036 KB Output is correct
39 Correct 157 ms 51824 KB Output is correct
40 Correct 96 ms 50244 KB Output is correct
41 Correct 95 ms 50132 KB Output is correct
42 Correct 82 ms 49604 KB Output is correct
43 Correct 83 ms 49568 KB Output is correct
44 Correct 97 ms 50124 KB Output is correct
45 Correct 98 ms 50040 KB Output is correct
46 Correct 84 ms 49620 KB Output is correct
47 Correct 83 ms 49492 KB Output is correct
48 Execution timed out 2574 ms 100264 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47204 KB Output is correct
2 Correct 28 ms 47200 KB Output is correct
3 Correct 28 ms 47196 KB Output is correct
4 Correct 28 ms 47308 KB Output is correct
5 Correct 29 ms 47276 KB Output is correct
6 Correct 29 ms 47212 KB Output is correct
7 Correct 28 ms 47264 KB Output is correct
8 Correct 28 ms 47292 KB Output is correct
9 Correct 28 ms 47292 KB Output is correct
10 Correct 28 ms 47308 KB Output is correct
11 Correct 27 ms 47180 KB Output is correct
12 Correct 27 ms 47212 KB Output is correct
13 Correct 28 ms 47192 KB Output is correct
14 Correct 29 ms 47208 KB Output is correct
15 Correct 29 ms 47236 KB Output is correct
16 Correct 28 ms 47252 KB Output is correct
17 Correct 28 ms 47308 KB Output is correct
18 Correct 27 ms 47308 KB Output is correct
19 Correct 28 ms 47180 KB Output is correct
20 Correct 29 ms 47296 KB Output is correct
21 Correct 28 ms 47308 KB Output is correct
22 Correct 27 ms 47300 KB Output is correct
23 Correct 28 ms 47272 KB Output is correct
24 Correct 28 ms 47196 KB Output is correct
25 Correct 29 ms 47196 KB Output is correct
26 Correct 29 ms 47232 KB Output is correct
27 Correct 39 ms 47872 KB Output is correct
28 Correct 36 ms 47896 KB Output is correct
29 Correct 40 ms 47820 KB Output is correct
30 Correct 42 ms 47808 KB Output is correct
31 Correct 40 ms 47812 KB Output is correct
32 Correct 37 ms 47844 KB Output is correct
33 Correct 39 ms 47876 KB Output is correct
34 Correct 39 ms 47876 KB Output is correct
35 Correct 159 ms 52000 KB Output is correct
36 Correct 171 ms 51908 KB Output is correct
37 Correct 165 ms 51888 KB Output is correct
38 Correct 156 ms 52036 KB Output is correct
39 Correct 157 ms 51824 KB Output is correct
40 Correct 96 ms 50244 KB Output is correct
41 Correct 95 ms 50132 KB Output is correct
42 Correct 82 ms 49604 KB Output is correct
43 Correct 83 ms 49568 KB Output is correct
44 Correct 97 ms 50124 KB Output is correct
45 Correct 98 ms 50040 KB Output is correct
46 Correct 84 ms 49620 KB Output is correct
47 Correct 83 ms 49492 KB Output is correct
48 Execution timed out 2574 ms 100264 KB Time limit exceeded
49 Halted 0 ms 0 KB -