# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
397578 |
2021-05-02T12:28:02 Z |
timmyfeng |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
116708 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int color[N], tally[N], ans[N];
vector<int> pairs[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> color[i];
++tally[color[i]];
}
multiset<int> maxi = {0};
for (int i = 1; i <= m; ++i) {
maxi.insert(tally[i]);
ans[i] = INT_MAX;
}
for (int k = 0; k < 2; ++k) {
fill(pairs, pairs + m + 1, vector<int>());
for (int i = k; i + 2 <= n; i += 2) {
if (color[i] != color[i + 1]) {
pairs[color[i]].push_back(color[i + 1]);
pairs[color[i + 1]].push_back(color[i]);
}
}
for (int i = 1; i <= m; ++i) {
maxi.erase(maxi.find(tally[i]));
sort(pairs[i].begin(), pairs[i].end());
for (int j = 0, k = 0; j < (int) pairs[i].size(); j = k) {
while (k < (int) pairs[i].size() && pairs[i][j] == pairs[i][k]) {
++k;
}
maxi.erase(maxi.find(tally[pairs[i][j]]));
maxi.insert(tally[pairs[i][j]] - (k - j));
}
ans[i] = min(ans[i], n - tally[i] - *(--maxi.end()));
for (int j = 0, k = 0; j < (int) pairs[i].size(); j = k) {
while (k < (int) pairs[i].size() && pairs[i][j] == pairs[i][k]) {
++k;
}
maxi.erase(maxi.find(tally[pairs[i][j]] - (k - j)));
maxi.insert(tally[pairs[i][j]]);
}
maxi.insert(tally[i]);
}
}
for (int i = 1; i <= m; ++i) {
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
15 ms |
23756 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23700 KB |
Output is correct |
7 |
Correct |
15 ms |
23824 KB |
Output is correct |
8 |
Correct |
15 ms |
23744 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23716 KB |
Output is correct |
13 |
Correct |
15 ms |
23724 KB |
Output is correct |
14 |
Correct |
15 ms |
23824 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
14 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23740 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23820 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
16 ms |
23756 KB |
Output is correct |
22 |
Correct |
15 ms |
23732 KB |
Output is correct |
23 |
Correct |
15 ms |
23712 KB |
Output is correct |
24 |
Correct |
15 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23756 KB |
Output is correct |
26 |
Correct |
15 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
15 ms |
23756 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23700 KB |
Output is correct |
7 |
Correct |
15 ms |
23824 KB |
Output is correct |
8 |
Correct |
15 ms |
23744 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23716 KB |
Output is correct |
13 |
Correct |
15 ms |
23724 KB |
Output is correct |
14 |
Correct |
15 ms |
23824 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
14 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23740 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23820 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
16 ms |
23756 KB |
Output is correct |
22 |
Correct |
15 ms |
23732 KB |
Output is correct |
23 |
Correct |
15 ms |
23712 KB |
Output is correct |
24 |
Correct |
15 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23756 KB |
Output is correct |
26 |
Correct |
15 ms |
23808 KB |
Output is correct |
27 |
Correct |
28 ms |
24780 KB |
Output is correct |
28 |
Correct |
26 ms |
24640 KB |
Output is correct |
29 |
Correct |
28 ms |
24772 KB |
Output is correct |
30 |
Correct |
26 ms |
24524 KB |
Output is correct |
31 |
Correct |
28 ms |
24696 KB |
Output is correct |
32 |
Correct |
27 ms |
24652 KB |
Output is correct |
33 |
Correct |
28 ms |
24772 KB |
Output is correct |
34 |
Correct |
26 ms |
24616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
15 ms |
23756 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23700 KB |
Output is correct |
7 |
Correct |
15 ms |
23824 KB |
Output is correct |
8 |
Correct |
15 ms |
23744 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23716 KB |
Output is correct |
13 |
Correct |
15 ms |
23724 KB |
Output is correct |
14 |
Correct |
15 ms |
23824 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
14 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23740 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23820 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
16 ms |
23756 KB |
Output is correct |
22 |
Correct |
15 ms |
23732 KB |
Output is correct |
23 |
Correct |
15 ms |
23712 KB |
Output is correct |
24 |
Correct |
15 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23756 KB |
Output is correct |
26 |
Correct |
15 ms |
23808 KB |
Output is correct |
27 |
Correct |
28 ms |
24780 KB |
Output is correct |
28 |
Correct |
26 ms |
24640 KB |
Output is correct |
29 |
Correct |
28 ms |
24772 KB |
Output is correct |
30 |
Correct |
26 ms |
24524 KB |
Output is correct |
31 |
Correct |
28 ms |
24696 KB |
Output is correct |
32 |
Correct |
27 ms |
24652 KB |
Output is correct |
33 |
Correct |
28 ms |
24772 KB |
Output is correct |
34 |
Correct |
26 ms |
24616 KB |
Output is correct |
35 |
Correct |
96 ms |
24904 KB |
Output is correct |
36 |
Correct |
93 ms |
24800 KB |
Output is correct |
37 |
Correct |
92 ms |
24792 KB |
Output is correct |
38 |
Correct |
94 ms |
24788 KB |
Output is correct |
39 |
Correct |
93 ms |
24828 KB |
Output is correct |
40 |
Correct |
62 ms |
24900 KB |
Output is correct |
41 |
Correct |
62 ms |
24876 KB |
Output is correct |
42 |
Correct |
56 ms |
24792 KB |
Output is correct |
43 |
Correct |
54 ms |
24860 KB |
Output is correct |
44 |
Correct |
63 ms |
24912 KB |
Output is correct |
45 |
Correct |
68 ms |
24780 KB |
Output is correct |
46 |
Correct |
57 ms |
24844 KB |
Output is correct |
47 |
Correct |
55 ms |
24824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
15 ms |
23756 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23700 KB |
Output is correct |
7 |
Correct |
15 ms |
23824 KB |
Output is correct |
8 |
Correct |
15 ms |
23744 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23716 KB |
Output is correct |
13 |
Correct |
15 ms |
23724 KB |
Output is correct |
14 |
Correct |
15 ms |
23824 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
14 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23740 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23820 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
16 ms |
23756 KB |
Output is correct |
22 |
Correct |
15 ms |
23732 KB |
Output is correct |
23 |
Correct |
15 ms |
23712 KB |
Output is correct |
24 |
Correct |
15 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23756 KB |
Output is correct |
26 |
Correct |
15 ms |
23808 KB |
Output is correct |
27 |
Correct |
28 ms |
24780 KB |
Output is correct |
28 |
Correct |
26 ms |
24640 KB |
Output is correct |
29 |
Correct |
28 ms |
24772 KB |
Output is correct |
30 |
Correct |
26 ms |
24524 KB |
Output is correct |
31 |
Correct |
28 ms |
24696 KB |
Output is correct |
32 |
Correct |
27 ms |
24652 KB |
Output is correct |
33 |
Correct |
28 ms |
24772 KB |
Output is correct |
34 |
Correct |
26 ms |
24616 KB |
Output is correct |
35 |
Correct |
96 ms |
24904 KB |
Output is correct |
36 |
Correct |
93 ms |
24800 KB |
Output is correct |
37 |
Correct |
92 ms |
24792 KB |
Output is correct |
38 |
Correct |
94 ms |
24788 KB |
Output is correct |
39 |
Correct |
93 ms |
24828 KB |
Output is correct |
40 |
Correct |
62 ms |
24900 KB |
Output is correct |
41 |
Correct |
62 ms |
24876 KB |
Output is correct |
42 |
Correct |
56 ms |
24792 KB |
Output is correct |
43 |
Correct |
54 ms |
24860 KB |
Output is correct |
44 |
Correct |
63 ms |
24912 KB |
Output is correct |
45 |
Correct |
68 ms |
24780 KB |
Output is correct |
46 |
Correct |
57 ms |
24844 KB |
Output is correct |
47 |
Correct |
55 ms |
24824 KB |
Output is correct |
48 |
Correct |
1116 ms |
34548 KB |
Output is correct |
49 |
Correct |
1128 ms |
34552 KB |
Output is correct |
50 |
Correct |
1111 ms |
34628 KB |
Output is correct |
51 |
Correct |
949 ms |
34500 KB |
Output is correct |
52 |
Correct |
795 ms |
33524 KB |
Output is correct |
53 |
Correct |
621 ms |
33860 KB |
Output is correct |
54 |
Correct |
487 ms |
32836 KB |
Output is correct |
55 |
Correct |
464 ms |
32632 KB |
Output is correct |
56 |
Correct |
408 ms |
32324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
16 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
15 ms |
23756 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23700 KB |
Output is correct |
7 |
Correct |
15 ms |
23824 KB |
Output is correct |
8 |
Correct |
15 ms |
23744 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
16 ms |
23816 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23716 KB |
Output is correct |
13 |
Correct |
15 ms |
23724 KB |
Output is correct |
14 |
Correct |
15 ms |
23824 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
14 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23740 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23820 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
16 ms |
23756 KB |
Output is correct |
22 |
Correct |
15 ms |
23732 KB |
Output is correct |
23 |
Correct |
15 ms |
23712 KB |
Output is correct |
24 |
Correct |
15 ms |
23820 KB |
Output is correct |
25 |
Correct |
15 ms |
23756 KB |
Output is correct |
26 |
Correct |
15 ms |
23808 KB |
Output is correct |
27 |
Correct |
28 ms |
24780 KB |
Output is correct |
28 |
Correct |
26 ms |
24640 KB |
Output is correct |
29 |
Correct |
28 ms |
24772 KB |
Output is correct |
30 |
Correct |
26 ms |
24524 KB |
Output is correct |
31 |
Correct |
28 ms |
24696 KB |
Output is correct |
32 |
Correct |
27 ms |
24652 KB |
Output is correct |
33 |
Correct |
28 ms |
24772 KB |
Output is correct |
34 |
Correct |
26 ms |
24616 KB |
Output is correct |
35 |
Correct |
96 ms |
24904 KB |
Output is correct |
36 |
Correct |
93 ms |
24800 KB |
Output is correct |
37 |
Correct |
92 ms |
24792 KB |
Output is correct |
38 |
Correct |
94 ms |
24788 KB |
Output is correct |
39 |
Correct |
93 ms |
24828 KB |
Output is correct |
40 |
Correct |
62 ms |
24900 KB |
Output is correct |
41 |
Correct |
62 ms |
24876 KB |
Output is correct |
42 |
Correct |
56 ms |
24792 KB |
Output is correct |
43 |
Correct |
54 ms |
24860 KB |
Output is correct |
44 |
Correct |
63 ms |
24912 KB |
Output is correct |
45 |
Correct |
68 ms |
24780 KB |
Output is correct |
46 |
Correct |
57 ms |
24844 KB |
Output is correct |
47 |
Correct |
55 ms |
24824 KB |
Output is correct |
48 |
Correct |
1116 ms |
34548 KB |
Output is correct |
49 |
Correct |
1128 ms |
34552 KB |
Output is correct |
50 |
Correct |
1111 ms |
34628 KB |
Output is correct |
51 |
Correct |
949 ms |
34500 KB |
Output is correct |
52 |
Correct |
795 ms |
33524 KB |
Output is correct |
53 |
Correct |
621 ms |
33860 KB |
Output is correct |
54 |
Correct |
487 ms |
32836 KB |
Output is correct |
55 |
Correct |
464 ms |
32632 KB |
Output is correct |
56 |
Correct |
408 ms |
32324 KB |
Output is correct |
57 |
Execution timed out |
2591 ms |
116708 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |