# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
397576 |
2021-05-02T12:25:00 Z |
timmyfeng |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
126504 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]));
for (auto j : pairs[i]) {
maxi.erase(maxi.find(tally[j]));
maxi.insert(--tally[j]);
}
ans[i] = min(ans[i], n - tally[i] - *(--maxi.end()));
for (auto j : pairs[i]) {
maxi.erase(maxi.find(tally[j]));
maxi.insert(++tally[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 |
15 ms |
23772 KB |
Output is correct |
3 |
Correct |
16 ms |
23760 KB |
Output is correct |
4 |
Correct |
16 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23708 KB |
Output is correct |
6 |
Correct |
15 ms |
23804 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
15 ms |
23820 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
15 ms |
23800 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23820 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
15 ms |
23756 KB |
Output is correct |
15 |
Correct |
15 ms |
23816 KB |
Output is correct |
16 |
Correct |
15 ms |
23720 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23808 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
15 ms |
23796 KB |
Output is correct |
22 |
Correct |
15 ms |
23784 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23748 KB |
Output is correct |
25 |
Correct |
15 ms |
23748 KB |
Output is correct |
26 |
Correct |
15 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23772 KB |
Output is correct |
3 |
Correct |
16 ms |
23760 KB |
Output is correct |
4 |
Correct |
16 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23708 KB |
Output is correct |
6 |
Correct |
15 ms |
23804 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
15 ms |
23820 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
15 ms |
23800 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23820 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
15 ms |
23756 KB |
Output is correct |
15 |
Correct |
15 ms |
23816 KB |
Output is correct |
16 |
Correct |
15 ms |
23720 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23808 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
15 ms |
23796 KB |
Output is correct |
22 |
Correct |
15 ms |
23784 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23748 KB |
Output is correct |
25 |
Correct |
15 ms |
23748 KB |
Output is correct |
26 |
Correct |
15 ms |
23756 KB |
Output is correct |
27 |
Correct |
54 ms |
24792 KB |
Output is correct |
28 |
Correct |
39 ms |
24680 KB |
Output is correct |
29 |
Correct |
50 ms |
24776 KB |
Output is correct |
30 |
Correct |
41 ms |
24608 KB |
Output is correct |
31 |
Correct |
52 ms |
24780 KB |
Output is correct |
32 |
Correct |
38 ms |
24748 KB |
Output is correct |
33 |
Correct |
51 ms |
24780 KB |
Output is correct |
34 |
Correct |
41 ms |
24536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23772 KB |
Output is correct |
3 |
Correct |
16 ms |
23760 KB |
Output is correct |
4 |
Correct |
16 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23708 KB |
Output is correct |
6 |
Correct |
15 ms |
23804 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
15 ms |
23820 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
15 ms |
23800 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23820 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
15 ms |
23756 KB |
Output is correct |
15 |
Correct |
15 ms |
23816 KB |
Output is correct |
16 |
Correct |
15 ms |
23720 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23808 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
15 ms |
23796 KB |
Output is correct |
22 |
Correct |
15 ms |
23784 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23748 KB |
Output is correct |
25 |
Correct |
15 ms |
23748 KB |
Output is correct |
26 |
Correct |
15 ms |
23756 KB |
Output is correct |
27 |
Correct |
54 ms |
24792 KB |
Output is correct |
28 |
Correct |
39 ms |
24680 KB |
Output is correct |
29 |
Correct |
50 ms |
24776 KB |
Output is correct |
30 |
Correct |
41 ms |
24608 KB |
Output is correct |
31 |
Correct |
52 ms |
24780 KB |
Output is correct |
32 |
Correct |
38 ms |
24748 KB |
Output is correct |
33 |
Correct |
51 ms |
24780 KB |
Output is correct |
34 |
Correct |
41 ms |
24536 KB |
Output is correct |
35 |
Correct |
98 ms |
24808 KB |
Output is correct |
36 |
Correct |
95 ms |
24804 KB |
Output is correct |
37 |
Correct |
95 ms |
24892 KB |
Output is correct |
38 |
Correct |
98 ms |
24804 KB |
Output is correct |
39 |
Correct |
95 ms |
24764 KB |
Output is correct |
40 |
Correct |
84 ms |
24772 KB |
Output is correct |
41 |
Correct |
81 ms |
24824 KB |
Output is correct |
42 |
Correct |
77 ms |
24864 KB |
Output is correct |
43 |
Correct |
80 ms |
24900 KB |
Output is correct |
44 |
Correct |
84 ms |
24884 KB |
Output is correct |
45 |
Correct |
82 ms |
24876 KB |
Output is correct |
46 |
Correct |
78 ms |
24780 KB |
Output is correct |
47 |
Correct |
80 ms |
24788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23772 KB |
Output is correct |
3 |
Correct |
16 ms |
23760 KB |
Output is correct |
4 |
Correct |
16 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23708 KB |
Output is correct |
6 |
Correct |
15 ms |
23804 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
15 ms |
23820 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
15 ms |
23800 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23820 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
15 ms |
23756 KB |
Output is correct |
15 |
Correct |
15 ms |
23816 KB |
Output is correct |
16 |
Correct |
15 ms |
23720 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23808 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
15 ms |
23796 KB |
Output is correct |
22 |
Correct |
15 ms |
23784 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23748 KB |
Output is correct |
25 |
Correct |
15 ms |
23748 KB |
Output is correct |
26 |
Correct |
15 ms |
23756 KB |
Output is correct |
27 |
Correct |
54 ms |
24792 KB |
Output is correct |
28 |
Correct |
39 ms |
24680 KB |
Output is correct |
29 |
Correct |
50 ms |
24776 KB |
Output is correct |
30 |
Correct |
41 ms |
24608 KB |
Output is correct |
31 |
Correct |
52 ms |
24780 KB |
Output is correct |
32 |
Correct |
38 ms |
24748 KB |
Output is correct |
33 |
Correct |
51 ms |
24780 KB |
Output is correct |
34 |
Correct |
41 ms |
24536 KB |
Output is correct |
35 |
Correct |
98 ms |
24808 KB |
Output is correct |
36 |
Correct |
95 ms |
24804 KB |
Output is correct |
37 |
Correct |
95 ms |
24892 KB |
Output is correct |
38 |
Correct |
98 ms |
24804 KB |
Output is correct |
39 |
Correct |
95 ms |
24764 KB |
Output is correct |
40 |
Correct |
84 ms |
24772 KB |
Output is correct |
41 |
Correct |
81 ms |
24824 KB |
Output is correct |
42 |
Correct |
77 ms |
24864 KB |
Output is correct |
43 |
Correct |
80 ms |
24900 KB |
Output is correct |
44 |
Correct |
84 ms |
24884 KB |
Output is correct |
45 |
Correct |
82 ms |
24876 KB |
Output is correct |
46 |
Correct |
78 ms |
24780 KB |
Output is correct |
47 |
Correct |
80 ms |
24788 KB |
Output is correct |
48 |
Correct |
1050 ms |
34548 KB |
Output is correct |
49 |
Correct |
1058 ms |
39092 KB |
Output is correct |
50 |
Correct |
1065 ms |
39108 KB |
Output is correct |
51 |
Correct |
996 ms |
38640 KB |
Output is correct |
52 |
Correct |
955 ms |
37328 KB |
Output is correct |
53 |
Correct |
800 ms |
38332 KB |
Output is correct |
54 |
Correct |
710 ms |
37316 KB |
Output is correct |
55 |
Correct |
698 ms |
37056 KB |
Output is correct |
56 |
Correct |
674 ms |
36804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23772 KB |
Output is correct |
3 |
Correct |
16 ms |
23760 KB |
Output is correct |
4 |
Correct |
16 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23708 KB |
Output is correct |
6 |
Correct |
15 ms |
23804 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
15 ms |
23820 KB |
Output is correct |
9 |
Correct |
16 ms |
23756 KB |
Output is correct |
10 |
Correct |
15 ms |
23800 KB |
Output is correct |
11 |
Correct |
15 ms |
23816 KB |
Output is correct |
12 |
Correct |
15 ms |
23820 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
15 ms |
23756 KB |
Output is correct |
15 |
Correct |
15 ms |
23816 KB |
Output is correct |
16 |
Correct |
15 ms |
23720 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
15 ms |
23756 KB |
Output is correct |
19 |
Correct |
15 ms |
23808 KB |
Output is correct |
20 |
Correct |
15 ms |
23756 KB |
Output is correct |
21 |
Correct |
15 ms |
23796 KB |
Output is correct |
22 |
Correct |
15 ms |
23784 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23748 KB |
Output is correct |
25 |
Correct |
15 ms |
23748 KB |
Output is correct |
26 |
Correct |
15 ms |
23756 KB |
Output is correct |
27 |
Correct |
54 ms |
24792 KB |
Output is correct |
28 |
Correct |
39 ms |
24680 KB |
Output is correct |
29 |
Correct |
50 ms |
24776 KB |
Output is correct |
30 |
Correct |
41 ms |
24608 KB |
Output is correct |
31 |
Correct |
52 ms |
24780 KB |
Output is correct |
32 |
Correct |
38 ms |
24748 KB |
Output is correct |
33 |
Correct |
51 ms |
24780 KB |
Output is correct |
34 |
Correct |
41 ms |
24536 KB |
Output is correct |
35 |
Correct |
98 ms |
24808 KB |
Output is correct |
36 |
Correct |
95 ms |
24804 KB |
Output is correct |
37 |
Correct |
95 ms |
24892 KB |
Output is correct |
38 |
Correct |
98 ms |
24804 KB |
Output is correct |
39 |
Correct |
95 ms |
24764 KB |
Output is correct |
40 |
Correct |
84 ms |
24772 KB |
Output is correct |
41 |
Correct |
81 ms |
24824 KB |
Output is correct |
42 |
Correct |
77 ms |
24864 KB |
Output is correct |
43 |
Correct |
80 ms |
24900 KB |
Output is correct |
44 |
Correct |
84 ms |
24884 KB |
Output is correct |
45 |
Correct |
82 ms |
24876 KB |
Output is correct |
46 |
Correct |
78 ms |
24780 KB |
Output is correct |
47 |
Correct |
80 ms |
24788 KB |
Output is correct |
48 |
Correct |
1050 ms |
34548 KB |
Output is correct |
49 |
Correct |
1058 ms |
39092 KB |
Output is correct |
50 |
Correct |
1065 ms |
39108 KB |
Output is correct |
51 |
Correct |
996 ms |
38640 KB |
Output is correct |
52 |
Correct |
955 ms |
37328 KB |
Output is correct |
53 |
Correct |
800 ms |
38332 KB |
Output is correct |
54 |
Correct |
710 ms |
37316 KB |
Output is correct |
55 |
Correct |
698 ms |
37056 KB |
Output is correct |
56 |
Correct |
674 ms |
36804 KB |
Output is correct |
57 |
Execution timed out |
2563 ms |
126504 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |