# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599103 |
2022-07-19T10:06:38 Z |
piOOE |
Rope (JOI17_rope) |
C++17 |
|
1291 ms |
234964 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000000, M = 10000000;
int a[N], ans[M], cnt[M];
vector<int> g[N];
priority_queue<pair<int, int>> pq;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(ans, 0x3f, sizeof(ans));
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
--a[i];
++cnt[a[i]];
}
for (int i = 0; i < m; ++i) {
pq.push({cnt[i], i});
}
for (int k = 0; k < 2; ++k) {
for (int i = 0; i < m; ++i) {
g[i].clear();
}
for (int i = k; i + 1 < n; i += 2) {
if (a[i] != a[i + 1]) {
g[a[i]].push_back(a[i + 1]);
g[a[i + 1]].push_back(a[i]);
}
}
for (int c = 0; c < m; ++c) {
int now = cnt[c];
auto upd = [](int v, int nw) {
pq.push({cnt[v] = nw, v});
};
upd(c, 0);
for (int to : g[c]) {
upd(to, cnt[to] - 1);
}
while (cnt[pq.top().second] != pq.top().first) {
pq.pop();
}
ans[c] = min(ans[c], n - now - pq.top().first);
upd(c, now);
for (int to : g[c]) {
upd(to, cnt[to] + 1);
}
}
}
for (int i = 0; i < m; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62924 KB |
Output is correct |
2 |
Correct |
28 ms |
62936 KB |
Output is correct |
3 |
Correct |
32 ms |
62888 KB |
Output is correct |
4 |
Correct |
31 ms |
62844 KB |
Output is correct |
5 |
Correct |
33 ms |
62852 KB |
Output is correct |
6 |
Correct |
33 ms |
62908 KB |
Output is correct |
7 |
Correct |
28 ms |
62884 KB |
Output is correct |
8 |
Correct |
33 ms |
62908 KB |
Output is correct |
9 |
Correct |
34 ms |
62932 KB |
Output is correct |
10 |
Correct |
33 ms |
62932 KB |
Output is correct |
11 |
Correct |
32 ms |
62948 KB |
Output is correct |
12 |
Correct |
32 ms |
62924 KB |
Output is correct |
13 |
Correct |
33 ms |
62944 KB |
Output is correct |
14 |
Correct |
29 ms |
62924 KB |
Output is correct |
15 |
Correct |
30 ms |
62932 KB |
Output is correct |
16 |
Correct |
29 ms |
62848 KB |
Output is correct |
17 |
Correct |
30 ms |
62904 KB |
Output is correct |
18 |
Correct |
32 ms |
62940 KB |
Output is correct |
19 |
Correct |
29 ms |
62876 KB |
Output is correct |
20 |
Correct |
27 ms |
62936 KB |
Output is correct |
21 |
Correct |
38 ms |
62932 KB |
Output is correct |
22 |
Correct |
35 ms |
62936 KB |
Output is correct |
23 |
Correct |
35 ms |
62844 KB |
Output is correct |
24 |
Correct |
34 ms |
62844 KB |
Output is correct |
25 |
Correct |
28 ms |
62924 KB |
Output is correct |
26 |
Correct |
28 ms |
62932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62924 KB |
Output is correct |
2 |
Correct |
28 ms |
62936 KB |
Output is correct |
3 |
Correct |
32 ms |
62888 KB |
Output is correct |
4 |
Correct |
31 ms |
62844 KB |
Output is correct |
5 |
Correct |
33 ms |
62852 KB |
Output is correct |
6 |
Correct |
33 ms |
62908 KB |
Output is correct |
7 |
Correct |
28 ms |
62884 KB |
Output is correct |
8 |
Correct |
33 ms |
62908 KB |
Output is correct |
9 |
Correct |
34 ms |
62932 KB |
Output is correct |
10 |
Correct |
33 ms |
62932 KB |
Output is correct |
11 |
Correct |
32 ms |
62948 KB |
Output is correct |
12 |
Correct |
32 ms |
62924 KB |
Output is correct |
13 |
Correct |
33 ms |
62944 KB |
Output is correct |
14 |
Correct |
29 ms |
62924 KB |
Output is correct |
15 |
Correct |
30 ms |
62932 KB |
Output is correct |
16 |
Correct |
29 ms |
62848 KB |
Output is correct |
17 |
Correct |
30 ms |
62904 KB |
Output is correct |
18 |
Correct |
32 ms |
62940 KB |
Output is correct |
19 |
Correct |
29 ms |
62876 KB |
Output is correct |
20 |
Correct |
27 ms |
62936 KB |
Output is correct |
21 |
Correct |
38 ms |
62932 KB |
Output is correct |
22 |
Correct |
35 ms |
62936 KB |
Output is correct |
23 |
Correct |
35 ms |
62844 KB |
Output is correct |
24 |
Correct |
34 ms |
62844 KB |
Output is correct |
25 |
Correct |
28 ms |
62924 KB |
Output is correct |
26 |
Correct |
28 ms |
62932 KB |
Output is correct |
27 |
Correct |
84 ms |
64764 KB |
Output is correct |
28 |
Correct |
66 ms |
64496 KB |
Output is correct |
29 |
Correct |
92 ms |
64640 KB |
Output is correct |
30 |
Correct |
77 ms |
64552 KB |
Output is correct |
31 |
Correct |
89 ms |
64744 KB |
Output is correct |
32 |
Correct |
73 ms |
64508 KB |
Output is correct |
33 |
Correct |
73 ms |
64612 KB |
Output is correct |
34 |
Correct |
77 ms |
64572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62924 KB |
Output is correct |
2 |
Correct |
28 ms |
62936 KB |
Output is correct |
3 |
Correct |
32 ms |
62888 KB |
Output is correct |
4 |
Correct |
31 ms |
62844 KB |
Output is correct |
5 |
Correct |
33 ms |
62852 KB |
Output is correct |
6 |
Correct |
33 ms |
62908 KB |
Output is correct |
7 |
Correct |
28 ms |
62884 KB |
Output is correct |
8 |
Correct |
33 ms |
62908 KB |
Output is correct |
9 |
Correct |
34 ms |
62932 KB |
Output is correct |
10 |
Correct |
33 ms |
62932 KB |
Output is correct |
11 |
Correct |
32 ms |
62948 KB |
Output is correct |
12 |
Correct |
32 ms |
62924 KB |
Output is correct |
13 |
Correct |
33 ms |
62944 KB |
Output is correct |
14 |
Correct |
29 ms |
62924 KB |
Output is correct |
15 |
Correct |
30 ms |
62932 KB |
Output is correct |
16 |
Correct |
29 ms |
62848 KB |
Output is correct |
17 |
Correct |
30 ms |
62904 KB |
Output is correct |
18 |
Correct |
32 ms |
62940 KB |
Output is correct |
19 |
Correct |
29 ms |
62876 KB |
Output is correct |
20 |
Correct |
27 ms |
62936 KB |
Output is correct |
21 |
Correct |
38 ms |
62932 KB |
Output is correct |
22 |
Correct |
35 ms |
62936 KB |
Output is correct |
23 |
Correct |
35 ms |
62844 KB |
Output is correct |
24 |
Correct |
34 ms |
62844 KB |
Output is correct |
25 |
Correct |
28 ms |
62924 KB |
Output is correct |
26 |
Correct |
28 ms |
62932 KB |
Output is correct |
27 |
Correct |
84 ms |
64764 KB |
Output is correct |
28 |
Correct |
66 ms |
64496 KB |
Output is correct |
29 |
Correct |
92 ms |
64640 KB |
Output is correct |
30 |
Correct |
77 ms |
64552 KB |
Output is correct |
31 |
Correct |
89 ms |
64744 KB |
Output is correct |
32 |
Correct |
73 ms |
64508 KB |
Output is correct |
33 |
Correct |
73 ms |
64612 KB |
Output is correct |
34 |
Correct |
77 ms |
64572 KB |
Output is correct |
35 |
Correct |
66 ms |
68476 KB |
Output is correct |
36 |
Correct |
55 ms |
68516 KB |
Output is correct |
37 |
Correct |
56 ms |
68448 KB |
Output is correct |
38 |
Correct |
54 ms |
68468 KB |
Output is correct |
39 |
Correct |
48 ms |
68484 KB |
Output is correct |
40 |
Correct |
91 ms |
66528 KB |
Output is correct |
41 |
Correct |
91 ms |
66468 KB |
Output is correct |
42 |
Correct |
84 ms |
65456 KB |
Output is correct |
43 |
Correct |
74 ms |
66568 KB |
Output is correct |
44 |
Correct |
59 ms |
68524 KB |
Output is correct |
45 |
Correct |
74 ms |
68544 KB |
Output is correct |
46 |
Correct |
72 ms |
66508 KB |
Output is correct |
47 |
Correct |
70 ms |
68596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62924 KB |
Output is correct |
2 |
Correct |
28 ms |
62936 KB |
Output is correct |
3 |
Correct |
32 ms |
62888 KB |
Output is correct |
4 |
Correct |
31 ms |
62844 KB |
Output is correct |
5 |
Correct |
33 ms |
62852 KB |
Output is correct |
6 |
Correct |
33 ms |
62908 KB |
Output is correct |
7 |
Correct |
28 ms |
62884 KB |
Output is correct |
8 |
Correct |
33 ms |
62908 KB |
Output is correct |
9 |
Correct |
34 ms |
62932 KB |
Output is correct |
10 |
Correct |
33 ms |
62932 KB |
Output is correct |
11 |
Correct |
32 ms |
62948 KB |
Output is correct |
12 |
Correct |
32 ms |
62924 KB |
Output is correct |
13 |
Correct |
33 ms |
62944 KB |
Output is correct |
14 |
Correct |
29 ms |
62924 KB |
Output is correct |
15 |
Correct |
30 ms |
62932 KB |
Output is correct |
16 |
Correct |
29 ms |
62848 KB |
Output is correct |
17 |
Correct |
30 ms |
62904 KB |
Output is correct |
18 |
Correct |
32 ms |
62940 KB |
Output is correct |
19 |
Correct |
29 ms |
62876 KB |
Output is correct |
20 |
Correct |
27 ms |
62936 KB |
Output is correct |
21 |
Correct |
38 ms |
62932 KB |
Output is correct |
22 |
Correct |
35 ms |
62936 KB |
Output is correct |
23 |
Correct |
35 ms |
62844 KB |
Output is correct |
24 |
Correct |
34 ms |
62844 KB |
Output is correct |
25 |
Correct |
28 ms |
62924 KB |
Output is correct |
26 |
Correct |
28 ms |
62932 KB |
Output is correct |
27 |
Correct |
84 ms |
64764 KB |
Output is correct |
28 |
Correct |
66 ms |
64496 KB |
Output is correct |
29 |
Correct |
92 ms |
64640 KB |
Output is correct |
30 |
Correct |
77 ms |
64552 KB |
Output is correct |
31 |
Correct |
89 ms |
64744 KB |
Output is correct |
32 |
Correct |
73 ms |
64508 KB |
Output is correct |
33 |
Correct |
73 ms |
64612 KB |
Output is correct |
34 |
Correct |
77 ms |
64572 KB |
Output is correct |
35 |
Correct |
66 ms |
68476 KB |
Output is correct |
36 |
Correct |
55 ms |
68516 KB |
Output is correct |
37 |
Correct |
56 ms |
68448 KB |
Output is correct |
38 |
Correct |
54 ms |
68468 KB |
Output is correct |
39 |
Correct |
48 ms |
68484 KB |
Output is correct |
40 |
Correct |
91 ms |
66528 KB |
Output is correct |
41 |
Correct |
91 ms |
66468 KB |
Output is correct |
42 |
Correct |
84 ms |
65456 KB |
Output is correct |
43 |
Correct |
74 ms |
66568 KB |
Output is correct |
44 |
Correct |
59 ms |
68524 KB |
Output is correct |
45 |
Correct |
74 ms |
68544 KB |
Output is correct |
46 |
Correct |
72 ms |
66508 KB |
Output is correct |
47 |
Correct |
70 ms |
68596 KB |
Output is correct |
48 |
Correct |
261 ms |
108088 KB |
Output is correct |
49 |
Correct |
278 ms |
108180 KB |
Output is correct |
50 |
Correct |
286 ms |
108148 KB |
Output is correct |
51 |
Correct |
301 ms |
108300 KB |
Output is correct |
52 |
Correct |
266 ms |
107036 KB |
Output is correct |
53 |
Correct |
577 ms |
90780 KB |
Output is correct |
54 |
Correct |
652 ms |
89896 KB |
Output is correct |
55 |
Correct |
626 ms |
81440 KB |
Output is correct |
56 |
Correct |
696 ms |
81168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62924 KB |
Output is correct |
2 |
Correct |
28 ms |
62936 KB |
Output is correct |
3 |
Correct |
32 ms |
62888 KB |
Output is correct |
4 |
Correct |
31 ms |
62844 KB |
Output is correct |
5 |
Correct |
33 ms |
62852 KB |
Output is correct |
6 |
Correct |
33 ms |
62908 KB |
Output is correct |
7 |
Correct |
28 ms |
62884 KB |
Output is correct |
8 |
Correct |
33 ms |
62908 KB |
Output is correct |
9 |
Correct |
34 ms |
62932 KB |
Output is correct |
10 |
Correct |
33 ms |
62932 KB |
Output is correct |
11 |
Correct |
32 ms |
62948 KB |
Output is correct |
12 |
Correct |
32 ms |
62924 KB |
Output is correct |
13 |
Correct |
33 ms |
62944 KB |
Output is correct |
14 |
Correct |
29 ms |
62924 KB |
Output is correct |
15 |
Correct |
30 ms |
62932 KB |
Output is correct |
16 |
Correct |
29 ms |
62848 KB |
Output is correct |
17 |
Correct |
30 ms |
62904 KB |
Output is correct |
18 |
Correct |
32 ms |
62940 KB |
Output is correct |
19 |
Correct |
29 ms |
62876 KB |
Output is correct |
20 |
Correct |
27 ms |
62936 KB |
Output is correct |
21 |
Correct |
38 ms |
62932 KB |
Output is correct |
22 |
Correct |
35 ms |
62936 KB |
Output is correct |
23 |
Correct |
35 ms |
62844 KB |
Output is correct |
24 |
Correct |
34 ms |
62844 KB |
Output is correct |
25 |
Correct |
28 ms |
62924 KB |
Output is correct |
26 |
Correct |
28 ms |
62932 KB |
Output is correct |
27 |
Correct |
84 ms |
64764 KB |
Output is correct |
28 |
Correct |
66 ms |
64496 KB |
Output is correct |
29 |
Correct |
92 ms |
64640 KB |
Output is correct |
30 |
Correct |
77 ms |
64552 KB |
Output is correct |
31 |
Correct |
89 ms |
64744 KB |
Output is correct |
32 |
Correct |
73 ms |
64508 KB |
Output is correct |
33 |
Correct |
73 ms |
64612 KB |
Output is correct |
34 |
Correct |
77 ms |
64572 KB |
Output is correct |
35 |
Correct |
66 ms |
68476 KB |
Output is correct |
36 |
Correct |
55 ms |
68516 KB |
Output is correct |
37 |
Correct |
56 ms |
68448 KB |
Output is correct |
38 |
Correct |
54 ms |
68468 KB |
Output is correct |
39 |
Correct |
48 ms |
68484 KB |
Output is correct |
40 |
Correct |
91 ms |
66528 KB |
Output is correct |
41 |
Correct |
91 ms |
66468 KB |
Output is correct |
42 |
Correct |
84 ms |
65456 KB |
Output is correct |
43 |
Correct |
74 ms |
66568 KB |
Output is correct |
44 |
Correct |
59 ms |
68524 KB |
Output is correct |
45 |
Correct |
74 ms |
68544 KB |
Output is correct |
46 |
Correct |
72 ms |
66508 KB |
Output is correct |
47 |
Correct |
70 ms |
68596 KB |
Output is correct |
48 |
Correct |
261 ms |
108088 KB |
Output is correct |
49 |
Correct |
278 ms |
108180 KB |
Output is correct |
50 |
Correct |
286 ms |
108148 KB |
Output is correct |
51 |
Correct |
301 ms |
108300 KB |
Output is correct |
52 |
Correct |
266 ms |
107036 KB |
Output is correct |
53 |
Correct |
577 ms |
90780 KB |
Output is correct |
54 |
Correct |
652 ms |
89896 KB |
Output is correct |
55 |
Correct |
626 ms |
81440 KB |
Output is correct |
56 |
Correct |
696 ms |
81168 KB |
Output is correct |
57 |
Correct |
1291 ms |
234964 KB |
Output is correct |
58 |
Correct |
1130 ms |
160352 KB |
Output is correct |
59 |
Correct |
1008 ms |
160280 KB |
Output is correct |
60 |
Correct |
1039 ms |
163832 KB |
Output is correct |
61 |
Correct |
1191 ms |
163896 KB |
Output is correct |
62 |
Correct |
882 ms |
119804 KB |
Output is correct |
63 |
Correct |
936 ms |
156444 KB |
Output is correct |
64 |
Correct |
920 ms |
121444 KB |
Output is correct |
65 |
Correct |
778 ms |
98536 KB |
Output is correct |