Submission #837297

# Submission time Handle Problem Language Result Execution time Memory
837297 2023-08-25T09:21:39 Z unnick Rope (JOI17_rope) C++14
45 / 100
2500 ms 980 KB
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> colors(n);
    vector<int> color_counts(m, 0);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        colors[i] = tmp-1;
        color_counts[tmp-1]++;
    }
    if (m == 1) {
        cout << "0\n";
        return 0;
    }
    vector<int> answers(m, 2000000000);
    for (int q = 0; q < 2; q++) {
        // cout << "q=" << q << "\n";
        // vector<int> col_ngb;
        // for (int i = q; i < n-1; q+=2) {
        //     int a = colors[i];
        //     int b = colors[i+1];
        //     if (a==b) continue;
        //     col_ngb[a]++;
        //     col_ngb[b]++;
        // }
        for (int c = 0; c < m; c++) {
            // cout << " c=" << c << "\n";
            int dom = -1;
            int domc = 0;
            for (int d = 0; d < m; d++) {
                if (d==c) continue;
                // cout << "  d=" << d << "\n";
                int count = n&1?q?(colors[0]==d):(colors[n-1]==d):q?((colors[0]==d)+(colors[n-1]==d)):0;
                for (int i = q; i < n-1; i+=2) {
                    int a = colors[i];
                    int b = colors[i+1];
                    if (a==c || b==c) continue;
                    if (a == d) count++;
                    if (b == d) count++;
                }
                // cout << "   " << count << "\n";
                if(count > domc) {
                    domc = count;
                    dom = d;
                }
            }
            answers[c] = min(answers[c], n-color_counts[c]-domc);
            // cout << n - color_counts[c] - domc << "\n";
        }
    }
    for (int a : answers) {
        cout << a << "\n";
    }
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:34:17: warning: variable 'dom' set but not used [-Wunused-but-set-variable]
   34 |             int dom = -1;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 33 ms 852 KB Output is correct
28 Correct 16 ms 876 KB Output is correct
29 Correct 30 ms 900 KB Output is correct
30 Correct 19 ms 852 KB Output is correct
31 Correct 37 ms 852 KB Output is correct
32 Correct 18 ms 852 KB Output is correct
33 Correct 39 ms 876 KB Output is correct
34 Correct 26 ms 872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 33 ms 852 KB Output is correct
28 Correct 16 ms 876 KB Output is correct
29 Correct 30 ms 900 KB Output is correct
30 Correct 19 ms 852 KB Output is correct
31 Correct 37 ms 852 KB Output is correct
32 Correct 18 ms 852 KB Output is correct
33 Correct 39 ms 876 KB Output is correct
34 Correct 26 ms 872 KB Output is correct
35 Execution timed out 2540 ms 980 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 33 ms 852 KB Output is correct
28 Correct 16 ms 876 KB Output is correct
29 Correct 30 ms 900 KB Output is correct
30 Correct 19 ms 852 KB Output is correct
31 Correct 37 ms 852 KB Output is correct
32 Correct 18 ms 852 KB Output is correct
33 Correct 39 ms 876 KB Output is correct
34 Correct 26 ms 872 KB Output is correct
35 Execution timed out 2540 ms 980 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 33 ms 852 KB Output is correct
28 Correct 16 ms 876 KB Output is correct
29 Correct 30 ms 900 KB Output is correct
30 Correct 19 ms 852 KB Output is correct
31 Correct 37 ms 852 KB Output is correct
32 Correct 18 ms 852 KB Output is correct
33 Correct 39 ms 876 KB Output is correct
34 Correct 26 ms 872 KB Output is correct
35 Execution timed out 2540 ms 980 KB Time limit exceeded
36 Halted 0 ms 0 KB -