# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128129 |
2019-07-10T12:52:35 Z |
EntityIT |
Rope (JOI17_rope) |
C++14 |
|
1160 ms |
136716 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, Cnt, order;
vector<bool> existed;
vector< vector<int> > vec[2];
bool cmp (int i, int j) { return cnt[i] > cnt[j]; }
int solve (int col, bool _) {
int cnt_rem = n - cnt[col] - (int)vec[_][col].size();
for (int _col : vec[_][col]) ++Cnt[_col], existed[_col] = 1;
Cnt[col] = cnt[col]; existed[col] = 1;
int mx = 0;
for (int i = 0; i < m; ++i) {
if (existed[ order[i] ]) mx = max(mx, cnt[ order[i] ] - Cnt[ order[i] ]);
else { mx = max(mx, cnt[ order[i] ]); break; }
}
cnt_rem -= mx;
for (int _col : vec[_][col]) Cnt[_col] = 0, existed[_col] = 0;
Cnt[col] = 0; existed[col] = 0;
return cnt_rem + (int)vec[_][col].size();
}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
existed.assign(m, 0);
order.assign(m, 0);
Cnt.assign(m, 0);
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>() );
vector<int> sz_vec(m, 0);
for (int i = _; i + 1 < n; i += 2) {
if (c[i] != c[i + 1]) {
++sz_vec[ c[i] ];
++sz_vec[ c[i + 1] ];
}
}
for (int i = 0; i < m; ++i) vec[_][i].assign(sz_vec[i], 0);
sz_vec.assign(m, 0);
for (int i = _; i + 1 < n; i += 2) {
if (c[i] != c[i + 1]) {
vec[_][ c[i] ][ sz_vec[ c[i] ]++ ] = c[i + 1];
vec[_][ c[i + 1] ][ sz_vec[ c[i + 1] ]++ ] = c[i];
}
}
}
for (int i = 0; i < m; ++i) order[i] = i;
sort(order.begin(), order.end(), cmp);
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 |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
352 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 |
256 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 |
252 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 |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
352 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 |
256 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 |
252 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
1400 KB |
Output is correct |
28 |
Correct |
14 ms |
1320 KB |
Output is correct |
29 |
Correct |
14 ms |
1432 KB |
Output is correct |
30 |
Correct |
13 ms |
1400 KB |
Output is correct |
31 |
Correct |
14 ms |
1400 KB |
Output is correct |
32 |
Correct |
13 ms |
1272 KB |
Output is correct |
33 |
Correct |
14 ms |
1448 KB |
Output is correct |
34 |
Correct |
14 ms |
1400 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 |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
352 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 |
256 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 |
252 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
1400 KB |
Output is correct |
28 |
Correct |
14 ms |
1320 KB |
Output is correct |
29 |
Correct |
14 ms |
1432 KB |
Output is correct |
30 |
Correct |
13 ms |
1400 KB |
Output is correct |
31 |
Correct |
14 ms |
1400 KB |
Output is correct |
32 |
Correct |
13 ms |
1272 KB |
Output is correct |
33 |
Correct |
14 ms |
1448 KB |
Output is correct |
34 |
Correct |
14 ms |
1400 KB |
Output is correct |
35 |
Correct |
17 ms |
1528 KB |
Output is correct |
36 |
Correct |
16 ms |
1528 KB |
Output is correct |
37 |
Correct |
16 ms |
1528 KB |
Output is correct |
38 |
Correct |
17 ms |
1532 KB |
Output is correct |
39 |
Correct |
17 ms |
1528 KB |
Output is correct |
40 |
Correct |
18 ms |
1528 KB |
Output is correct |
41 |
Correct |
16 ms |
1528 KB |
Output is correct |
42 |
Correct |
16 ms |
1532 KB |
Output is correct |
43 |
Correct |
16 ms |
1528 KB |
Output is correct |
44 |
Correct |
16 ms |
1528 KB |
Output is correct |
45 |
Correct |
17 ms |
1656 KB |
Output is correct |
46 |
Correct |
17 ms |
1528 KB |
Output is correct |
47 |
Correct |
19 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 |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
352 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 |
256 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 |
252 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
1400 KB |
Output is correct |
28 |
Correct |
14 ms |
1320 KB |
Output is correct |
29 |
Correct |
14 ms |
1432 KB |
Output is correct |
30 |
Correct |
13 ms |
1400 KB |
Output is correct |
31 |
Correct |
14 ms |
1400 KB |
Output is correct |
32 |
Correct |
13 ms |
1272 KB |
Output is correct |
33 |
Correct |
14 ms |
1448 KB |
Output is correct |
34 |
Correct |
14 ms |
1400 KB |
Output is correct |
35 |
Correct |
17 ms |
1528 KB |
Output is correct |
36 |
Correct |
16 ms |
1528 KB |
Output is correct |
37 |
Correct |
16 ms |
1528 KB |
Output is correct |
38 |
Correct |
17 ms |
1532 KB |
Output is correct |
39 |
Correct |
17 ms |
1528 KB |
Output is correct |
40 |
Correct |
18 ms |
1528 KB |
Output is correct |
41 |
Correct |
16 ms |
1528 KB |
Output is correct |
42 |
Correct |
16 ms |
1532 KB |
Output is correct |
43 |
Correct |
16 ms |
1528 KB |
Output is correct |
44 |
Correct |
16 ms |
1528 KB |
Output is correct |
45 |
Correct |
17 ms |
1656 KB |
Output is correct |
46 |
Correct |
17 ms |
1528 KB |
Output is correct |
47 |
Correct |
19 ms |
1528 KB |
Output is correct |
48 |
Correct |
227 ms |
12472 KB |
Output is correct |
49 |
Correct |
188 ms |
12452 KB |
Output is correct |
50 |
Correct |
192 ms |
12564 KB |
Output is correct |
51 |
Correct |
171 ms |
12408 KB |
Output is correct |
52 |
Correct |
155 ms |
12292 KB |
Output is correct |
53 |
Correct |
168 ms |
12408 KB |
Output is correct |
54 |
Correct |
164 ms |
12412 KB |
Output is correct |
55 |
Correct |
160 ms |
12408 KB |
Output is correct |
56 |
Correct |
160 ms |
12536 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 |
256 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 |
372 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
352 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 |
256 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 |
252 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
1400 KB |
Output is correct |
28 |
Correct |
14 ms |
1320 KB |
Output is correct |
29 |
Correct |
14 ms |
1432 KB |
Output is correct |
30 |
Correct |
13 ms |
1400 KB |
Output is correct |
31 |
Correct |
14 ms |
1400 KB |
Output is correct |
32 |
Correct |
13 ms |
1272 KB |
Output is correct |
33 |
Correct |
14 ms |
1448 KB |
Output is correct |
34 |
Correct |
14 ms |
1400 KB |
Output is correct |
35 |
Correct |
17 ms |
1528 KB |
Output is correct |
36 |
Correct |
16 ms |
1528 KB |
Output is correct |
37 |
Correct |
16 ms |
1528 KB |
Output is correct |
38 |
Correct |
17 ms |
1532 KB |
Output is correct |
39 |
Correct |
17 ms |
1528 KB |
Output is correct |
40 |
Correct |
18 ms |
1528 KB |
Output is correct |
41 |
Correct |
16 ms |
1528 KB |
Output is correct |
42 |
Correct |
16 ms |
1532 KB |
Output is correct |
43 |
Correct |
16 ms |
1528 KB |
Output is correct |
44 |
Correct |
16 ms |
1528 KB |
Output is correct |
45 |
Correct |
17 ms |
1656 KB |
Output is correct |
46 |
Correct |
17 ms |
1528 KB |
Output is correct |
47 |
Correct |
19 ms |
1528 KB |
Output is correct |
48 |
Correct |
227 ms |
12472 KB |
Output is correct |
49 |
Correct |
188 ms |
12452 KB |
Output is correct |
50 |
Correct |
192 ms |
12564 KB |
Output is correct |
51 |
Correct |
171 ms |
12408 KB |
Output is correct |
52 |
Correct |
155 ms |
12292 KB |
Output is correct |
53 |
Correct |
168 ms |
12408 KB |
Output is correct |
54 |
Correct |
164 ms |
12412 KB |
Output is correct |
55 |
Correct |
160 ms |
12408 KB |
Output is correct |
56 |
Correct |
160 ms |
12536 KB |
Output is correct |
57 |
Correct |
1160 ms |
136716 KB |
Output is correct |
58 |
Correct |
948 ms |
90452 KB |
Output is correct |
59 |
Correct |
854 ms |
90292 KB |
Output is correct |
60 |
Correct |
928 ms |
103540 KB |
Output is correct |
61 |
Correct |
937 ms |
103744 KB |
Output is correct |
62 |
Correct |
444 ms |
55148 KB |
Output is correct |
63 |
Correct |
708 ms |
69844 KB |
Output is correct |
64 |
Correct |
540 ms |
60664 KB |
Output is correct |
65 |
Correct |
316 ms |
37524 KB |
Output is correct |