# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128109 |
2019-07-10T12:32:52 Z |
EntityIT |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
172652 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;
vector<bool> existed;
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]) ++Cnt[_col];
for (int _col : vec[_][col]) if (!existed[_col]) {
existed[_col] = 1;
cnt_rem -= Cnt[_col];
upd(_col, -Cnt[_col]);
}
rem.erase(rem.find(cnt[col]) );
if (rem.size() ) cnt_rem -= *rem.rbegin();
rem.insert(cnt[col]);
for (int _col : vec[_][col]) if (existed[_col]) {
existed[_col] = 0;
upd(_col, Cnt[_col]);
Cnt[_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);
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 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 |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
252 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 |
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 |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
280 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
372 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
252 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
252 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 |
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 |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
280 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
372 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
252 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
14 ms |
1396 KB |
Output is correct |
28 |
Correct |
13 ms |
1372 KB |
Output is correct |
29 |
Correct |
14 ms |
1436 KB |
Output is correct |
30 |
Correct |
13 ms |
1388 KB |
Output is correct |
31 |
Correct |
14 ms |
1372 KB |
Output is correct |
32 |
Correct |
13 ms |
1304 KB |
Output is correct |
33 |
Correct |
14 ms |
1424 KB |
Output is correct |
34 |
Correct |
15 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
252 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 |
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 |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
280 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
372 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
252 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
14 ms |
1396 KB |
Output is correct |
28 |
Correct |
13 ms |
1372 KB |
Output is correct |
29 |
Correct |
14 ms |
1436 KB |
Output is correct |
30 |
Correct |
13 ms |
1388 KB |
Output is correct |
31 |
Correct |
14 ms |
1372 KB |
Output is correct |
32 |
Correct |
13 ms |
1304 KB |
Output is correct |
33 |
Correct |
14 ms |
1424 KB |
Output is correct |
34 |
Correct |
15 ms |
1292 KB |
Output is correct |
35 |
Correct |
95 ms |
1632 KB |
Output is correct |
36 |
Correct |
88 ms |
1636 KB |
Output is correct |
37 |
Correct |
88 ms |
1636 KB |
Output is correct |
38 |
Correct |
82 ms |
1632 KB |
Output is correct |
39 |
Correct |
105 ms |
1640 KB |
Output is correct |
40 |
Correct |
55 ms |
1596 KB |
Output is correct |
41 |
Correct |
50 ms |
1620 KB |
Output is correct |
42 |
Correct |
40 ms |
1528 KB |
Output is correct |
43 |
Correct |
41 ms |
1612 KB |
Output is correct |
44 |
Correct |
51 ms |
1632 KB |
Output is correct |
45 |
Correct |
50 ms |
1552 KB |
Output is correct |
46 |
Correct |
42 ms |
1500 KB |
Output is correct |
47 |
Correct |
41 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
252 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 |
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 |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
280 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
372 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
252 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
14 ms |
1396 KB |
Output is correct |
28 |
Correct |
13 ms |
1372 KB |
Output is correct |
29 |
Correct |
14 ms |
1436 KB |
Output is correct |
30 |
Correct |
13 ms |
1388 KB |
Output is correct |
31 |
Correct |
14 ms |
1372 KB |
Output is correct |
32 |
Correct |
13 ms |
1304 KB |
Output is correct |
33 |
Correct |
14 ms |
1424 KB |
Output is correct |
34 |
Correct |
15 ms |
1292 KB |
Output is correct |
35 |
Correct |
95 ms |
1632 KB |
Output is correct |
36 |
Correct |
88 ms |
1636 KB |
Output is correct |
37 |
Correct |
88 ms |
1636 KB |
Output is correct |
38 |
Correct |
82 ms |
1632 KB |
Output is correct |
39 |
Correct |
105 ms |
1640 KB |
Output is correct |
40 |
Correct |
55 ms |
1596 KB |
Output is correct |
41 |
Correct |
50 ms |
1620 KB |
Output is correct |
42 |
Correct |
40 ms |
1528 KB |
Output is correct |
43 |
Correct |
41 ms |
1612 KB |
Output is correct |
44 |
Correct |
51 ms |
1632 KB |
Output is correct |
45 |
Correct |
50 ms |
1552 KB |
Output is correct |
46 |
Correct |
42 ms |
1500 KB |
Output is correct |
47 |
Correct |
41 ms |
1528 KB |
Output is correct |
48 |
Correct |
1298 ms |
12544 KB |
Output is correct |
49 |
Correct |
1284 ms |
12528 KB |
Output is correct |
50 |
Correct |
1285 ms |
12540 KB |
Output is correct |
51 |
Correct |
1024 ms |
12332 KB |
Output is correct |
52 |
Correct |
805 ms |
12268 KB |
Output is correct |
53 |
Correct |
650 ms |
12528 KB |
Output is correct |
54 |
Correct |
468 ms |
12528 KB |
Output is correct |
55 |
Correct |
463 ms |
12504 KB |
Output is correct |
56 |
Correct |
378 ms |
12604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
324 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
252 KB |
Output is correct |
8 |
Correct |
2 ms |
252 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 |
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 |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
280 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
372 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
252 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
14 ms |
1396 KB |
Output is correct |
28 |
Correct |
13 ms |
1372 KB |
Output is correct |
29 |
Correct |
14 ms |
1436 KB |
Output is correct |
30 |
Correct |
13 ms |
1388 KB |
Output is correct |
31 |
Correct |
14 ms |
1372 KB |
Output is correct |
32 |
Correct |
13 ms |
1304 KB |
Output is correct |
33 |
Correct |
14 ms |
1424 KB |
Output is correct |
34 |
Correct |
15 ms |
1292 KB |
Output is correct |
35 |
Correct |
95 ms |
1632 KB |
Output is correct |
36 |
Correct |
88 ms |
1636 KB |
Output is correct |
37 |
Correct |
88 ms |
1636 KB |
Output is correct |
38 |
Correct |
82 ms |
1632 KB |
Output is correct |
39 |
Correct |
105 ms |
1640 KB |
Output is correct |
40 |
Correct |
55 ms |
1596 KB |
Output is correct |
41 |
Correct |
50 ms |
1620 KB |
Output is correct |
42 |
Correct |
40 ms |
1528 KB |
Output is correct |
43 |
Correct |
41 ms |
1612 KB |
Output is correct |
44 |
Correct |
51 ms |
1632 KB |
Output is correct |
45 |
Correct |
50 ms |
1552 KB |
Output is correct |
46 |
Correct |
42 ms |
1500 KB |
Output is correct |
47 |
Correct |
41 ms |
1528 KB |
Output is correct |
48 |
Correct |
1298 ms |
12544 KB |
Output is correct |
49 |
Correct |
1284 ms |
12528 KB |
Output is correct |
50 |
Correct |
1285 ms |
12540 KB |
Output is correct |
51 |
Correct |
1024 ms |
12332 KB |
Output is correct |
52 |
Correct |
805 ms |
12268 KB |
Output is correct |
53 |
Correct |
650 ms |
12528 KB |
Output is correct |
54 |
Correct |
468 ms |
12528 KB |
Output is correct |
55 |
Correct |
463 ms |
12504 KB |
Output is correct |
56 |
Correct |
378 ms |
12604 KB |
Output is correct |
57 |
Execution timed out |
2610 ms |
172652 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |