Submission #128066

# Submission time Handle Problem Language Result Execution time Memory
128066 2019-07-10T11:43:36 Z EntityIT Rope (JOI17_rope) C++14
80 / 100
2500 ms 168684 KB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back

using ii = pair<int, int>;
int n, m;
vector<int> c, cnt;
vector< vector<int> > vec[2];
multiset<int> rem;

void upd (int col, int val) {
    rem.erase(rem.find(cnt[col]) );
    cnt[col] += val;
    rem.insert(cnt[col]);
}

int solve (int col, bool _) {
    int cnt_rem = n - cnt[col];
    for (int _col : vec[_][col]) upd (_col, -1), --cnt_rem;
    rem.erase(rem.find(cnt[col]) );
    if (rem.size() ) cnt_rem -= *rem.rbegin();
    rem.insert(cnt[col]);
    for (int _col : vec[_][col]) upd (_col, 1);
    return cnt_rem + (int)vec[_][col].size();
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    cnt.assign(m, 0);
    c.assign(n, 0);
    for (int i = 0; i < n; ++i) cin >> c[i], --c[i], ++cnt[ c[i] ];

    for (int _ = 0; _ < 2; ++_) {
        vec[_].assign(m, vector<int>() );
        for (int i = _; i + 1 < n; i += 2) {
            if (c[i] != c[i + 1]) {
                vec[_][ c[i] ].pb(c[i + 1]);
                vec[_][ c[i + 1] ].pb(c[i]);
            }
        }
    }

    for (int col = 0; col < m; ++col) rem.insert(cnt[col]);

    for (int col = 0; col < m; ++col) cout << min(solve(col, 0), solve(col, 1) ) << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 47 ms 1912 KB Output is correct
28 Correct 34 ms 1656 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 35 ms 1528 KB Output is correct
31 Correct 51 ms 1912 KB Output is correct
32 Correct 32 ms 1660 KB Output is correct
33 Correct 44 ms 1784 KB Output is correct
34 Correct 36 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 47 ms 1912 KB Output is correct
28 Correct 34 ms 1656 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 35 ms 1528 KB Output is correct
31 Correct 51 ms 1912 KB Output is correct
32 Correct 32 ms 1660 KB Output is correct
33 Correct 44 ms 1784 KB Output is correct
34 Correct 36 ms 1528 KB Output is correct
35 Correct 99 ms 1912 KB Output is correct
36 Correct 99 ms 1924 KB Output is correct
37 Correct 101 ms 1880 KB Output is correct
38 Correct 103 ms 1784 KB Output is correct
39 Correct 99 ms 1912 KB Output is correct
40 Correct 81 ms 2040 KB Output is correct
41 Correct 83 ms 2168 KB Output is correct
42 Correct 76 ms 1912 KB Output is correct
43 Correct 78 ms 2168 KB Output is correct
44 Correct 84 ms 2040 KB Output is correct
45 Correct 84 ms 2088 KB Output is correct
46 Correct 78 ms 1912 KB Output is correct
47 Correct 79 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 47 ms 1912 KB Output is correct
28 Correct 34 ms 1656 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 35 ms 1528 KB Output is correct
31 Correct 51 ms 1912 KB Output is correct
32 Correct 32 ms 1660 KB Output is correct
33 Correct 44 ms 1784 KB Output is correct
34 Correct 36 ms 1528 KB Output is correct
35 Correct 99 ms 1912 KB Output is correct
36 Correct 99 ms 1924 KB Output is correct
37 Correct 101 ms 1880 KB Output is correct
38 Correct 103 ms 1784 KB Output is correct
39 Correct 99 ms 1912 KB Output is correct
40 Correct 81 ms 2040 KB Output is correct
41 Correct 83 ms 2168 KB Output is correct
42 Correct 76 ms 1912 KB Output is correct
43 Correct 78 ms 2168 KB Output is correct
44 Correct 84 ms 2040 KB Output is correct
45 Correct 84 ms 2088 KB Output is correct
46 Correct 78 ms 1912 KB Output is correct
47 Correct 79 ms 2040 KB Output is correct
48 Correct 1514 ms 17748 KB Output is correct
49 Correct 1520 ms 17656 KB Output is correct
50 Correct 1519 ms 17784 KB Output is correct
51 Correct 1275 ms 17628 KB Output is correct
52 Correct 1129 ms 14968 KB Output is correct
53 Correct 1053 ms 16120 KB Output is correct
54 Correct 938 ms 14308 KB Output is correct
55 Correct 903 ms 13844 KB Output is correct
56 Correct 807 ms 13332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 47 ms 1912 KB Output is correct
28 Correct 34 ms 1656 KB Output is correct
29 Correct 43 ms 1784 KB Output is correct
30 Correct 35 ms 1528 KB Output is correct
31 Correct 51 ms 1912 KB Output is correct
32 Correct 32 ms 1660 KB Output is correct
33 Correct 44 ms 1784 KB Output is correct
34 Correct 36 ms 1528 KB Output is correct
35 Correct 99 ms 1912 KB Output is correct
36 Correct 99 ms 1924 KB Output is correct
37 Correct 101 ms 1880 KB Output is correct
38 Correct 103 ms 1784 KB Output is correct
39 Correct 99 ms 1912 KB Output is correct
40 Correct 81 ms 2040 KB Output is correct
41 Correct 83 ms 2168 KB Output is correct
42 Correct 76 ms 1912 KB Output is correct
43 Correct 78 ms 2168 KB Output is correct
44 Correct 84 ms 2040 KB Output is correct
45 Correct 84 ms 2088 KB Output is correct
46 Correct 78 ms 1912 KB Output is correct
47 Correct 79 ms 2040 KB Output is correct
48 Correct 1514 ms 17748 KB Output is correct
49 Correct 1520 ms 17656 KB Output is correct
50 Correct 1519 ms 17784 KB Output is correct
51 Correct 1275 ms 17628 KB Output is correct
52 Correct 1129 ms 14968 KB Output is correct
53 Correct 1053 ms 16120 KB Output is correct
54 Correct 938 ms 14308 KB Output is correct
55 Correct 903 ms 13844 KB Output is correct
56 Correct 807 ms 13332 KB Output is correct
57 Execution timed out 2544 ms 168684 KB Time limit exceeded
58 Halted 0 ms 0 KB -