# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128063 |
2019-07-10T11:34:50 Z |
EntityIT |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
174228 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];
set<ii> rem;
void upd (int col, int val) {
rem.erase( { cnt[col], col } );
cnt[col] += val;
rem.insert( { cnt[col], col } );
}
int solve (int col, bool _) {
int cnt_rem = n - cnt[col];
for (int _col : vec[_][col]) upd (_col, -1), --cnt_rem;
rem.erase( { cnt[col], col } );
if (rem.size() ) cnt_rem -= (*rem.rbegin() ).fi;
rem.insert( { cnt[col], 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], 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
352 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 |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 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 |
376 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
352 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 |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
27 |
Correct |
57 ms |
2044 KB |
Output is correct |
28 |
Correct |
39 ms |
1784 KB |
Output is correct |
29 |
Correct |
53 ms |
2040 KB |
Output is correct |
30 |
Correct |
42 ms |
1656 KB |
Output is correct |
31 |
Correct |
56 ms |
2296 KB |
Output is correct |
32 |
Correct |
43 ms |
1788 KB |
Output is correct |
33 |
Correct |
54 ms |
2004 KB |
Output is correct |
34 |
Correct |
42 ms |
1656 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
352 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 |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
27 |
Correct |
57 ms |
2044 KB |
Output is correct |
28 |
Correct |
39 ms |
1784 KB |
Output is correct |
29 |
Correct |
53 ms |
2040 KB |
Output is correct |
30 |
Correct |
42 ms |
1656 KB |
Output is correct |
31 |
Correct |
56 ms |
2296 KB |
Output is correct |
32 |
Correct |
43 ms |
1788 KB |
Output is correct |
33 |
Correct |
54 ms |
2004 KB |
Output is correct |
34 |
Correct |
42 ms |
1656 KB |
Output is correct |
35 |
Correct |
132 ms |
2372 KB |
Output is correct |
36 |
Correct |
134 ms |
2304 KB |
Output is correct |
37 |
Correct |
134 ms |
2296 KB |
Output is correct |
38 |
Correct |
133 ms |
2296 KB |
Output is correct |
39 |
Correct |
133 ms |
2296 KB |
Output is correct |
40 |
Correct |
123 ms |
2424 KB |
Output is correct |
41 |
Correct |
122 ms |
2460 KB |
Output is correct |
42 |
Correct |
119 ms |
2424 KB |
Output is correct |
43 |
Correct |
119 ms |
2452 KB |
Output is correct |
44 |
Correct |
124 ms |
2424 KB |
Output is correct |
45 |
Correct |
126 ms |
2424 KB |
Output is correct |
46 |
Correct |
122 ms |
2388 KB |
Output is correct |
47 |
Correct |
122 ms |
2552 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
352 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 |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
27 |
Correct |
57 ms |
2044 KB |
Output is correct |
28 |
Correct |
39 ms |
1784 KB |
Output is correct |
29 |
Correct |
53 ms |
2040 KB |
Output is correct |
30 |
Correct |
42 ms |
1656 KB |
Output is correct |
31 |
Correct |
56 ms |
2296 KB |
Output is correct |
32 |
Correct |
43 ms |
1788 KB |
Output is correct |
33 |
Correct |
54 ms |
2004 KB |
Output is correct |
34 |
Correct |
42 ms |
1656 KB |
Output is correct |
35 |
Correct |
132 ms |
2372 KB |
Output is correct |
36 |
Correct |
134 ms |
2304 KB |
Output is correct |
37 |
Correct |
134 ms |
2296 KB |
Output is correct |
38 |
Correct |
133 ms |
2296 KB |
Output is correct |
39 |
Correct |
133 ms |
2296 KB |
Output is correct |
40 |
Correct |
123 ms |
2424 KB |
Output is correct |
41 |
Correct |
122 ms |
2460 KB |
Output is correct |
42 |
Correct |
119 ms |
2424 KB |
Output is correct |
43 |
Correct |
119 ms |
2452 KB |
Output is correct |
44 |
Correct |
124 ms |
2424 KB |
Output is correct |
45 |
Correct |
126 ms |
2424 KB |
Output is correct |
46 |
Correct |
122 ms |
2388 KB |
Output is correct |
47 |
Correct |
122 ms |
2552 KB |
Output is correct |
48 |
Correct |
1765 ms |
22456 KB |
Output is correct |
49 |
Correct |
1760 ms |
22136 KB |
Output is correct |
50 |
Correct |
1754 ms |
22264 KB |
Output is correct |
51 |
Correct |
1562 ms |
21676 KB |
Output is correct |
52 |
Correct |
1487 ms |
18924 KB |
Output is correct |
53 |
Correct |
1522 ms |
20472 KB |
Output is correct |
54 |
Correct |
1502 ms |
18552 KB |
Output is correct |
55 |
Correct |
1492 ms |
18296 KB |
Output is correct |
56 |
Correct |
1439 ms |
17912 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
352 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 |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
27 |
Correct |
57 ms |
2044 KB |
Output is correct |
28 |
Correct |
39 ms |
1784 KB |
Output is correct |
29 |
Correct |
53 ms |
2040 KB |
Output is correct |
30 |
Correct |
42 ms |
1656 KB |
Output is correct |
31 |
Correct |
56 ms |
2296 KB |
Output is correct |
32 |
Correct |
43 ms |
1788 KB |
Output is correct |
33 |
Correct |
54 ms |
2004 KB |
Output is correct |
34 |
Correct |
42 ms |
1656 KB |
Output is correct |
35 |
Correct |
132 ms |
2372 KB |
Output is correct |
36 |
Correct |
134 ms |
2304 KB |
Output is correct |
37 |
Correct |
134 ms |
2296 KB |
Output is correct |
38 |
Correct |
133 ms |
2296 KB |
Output is correct |
39 |
Correct |
133 ms |
2296 KB |
Output is correct |
40 |
Correct |
123 ms |
2424 KB |
Output is correct |
41 |
Correct |
122 ms |
2460 KB |
Output is correct |
42 |
Correct |
119 ms |
2424 KB |
Output is correct |
43 |
Correct |
119 ms |
2452 KB |
Output is correct |
44 |
Correct |
124 ms |
2424 KB |
Output is correct |
45 |
Correct |
126 ms |
2424 KB |
Output is correct |
46 |
Correct |
122 ms |
2388 KB |
Output is correct |
47 |
Correct |
122 ms |
2552 KB |
Output is correct |
48 |
Correct |
1765 ms |
22456 KB |
Output is correct |
49 |
Correct |
1760 ms |
22136 KB |
Output is correct |
50 |
Correct |
1754 ms |
22264 KB |
Output is correct |
51 |
Correct |
1562 ms |
21676 KB |
Output is correct |
52 |
Correct |
1487 ms |
18924 KB |
Output is correct |
53 |
Correct |
1522 ms |
20472 KB |
Output is correct |
54 |
Correct |
1502 ms |
18552 KB |
Output is correct |
55 |
Correct |
1492 ms |
18296 KB |
Output is correct |
56 |
Correct |
1439 ms |
17912 KB |
Output is correct |
57 |
Execution timed out |
2581 ms |
174228 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |