# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
614123 |
2022-07-30T19:17:14 Z |
valerikk |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
120552 KB |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> c(n);
for (int i = 0; i < n; ++i) {
cin >> c[i];
--c[i];
}
vector<int> cnt(m, 0);
for (int i = 0; i < n; ++i) {
++cnt[c[i]];
}
vector<int> ans(m);
for (int u = 0; u < m; ++u) {
ans[u] = n - cnt[u];
}
for (int p = 0; p < 2; ++p) {
map<pair<int, int>, int> mp;
vector<vector<int>> g(m);
for (int i = p; i + 1 < n; i += 2) {
if (c[i] != c[i + 1]) {
g[c[i]].push_back(c[i + 1]);
g[c[i + 1]].push_back(c[i]);
}
}
set<pair<int, int>> s;
for (int u = 0; u < m; ++u) {
s.insert({cnt[u], u});
}
for (int u = 0; u < m; ++u) {
sort(begin(g[u]), end(g[u]));
vector<int> tmp;
int len = 0;
for (int i = 0; i < (int) g[u].size(); ++i) {
int v = g[u][i];
++len;
if (i == (int) g[u].size() - 1 || g[u][i + 1] != v) {
ans[u] = min(ans[u], n - cnt[u] - cnt[v] + len);
len = 0;
tmp.push_back(v);
}
}
g[u] = tmp;
for (int v : g[u]) {
s.erase({cnt[v], v});
}
s.erase({cnt[u], u});
ans[u] = min(ans[u], n - cnt[u] - (s.empty() ? 0 : s.rbegin()->first));
s.insert({cnt[u], u});
for (int v : g[u]) {
s.insert({cnt[v], v});
}
}
}
for (int u = 0; u < m; ++u) {
cout << ans[u] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
12 ms |
1364 KB |
Output is correct |
28 |
Correct |
10 ms |
1244 KB |
Output is correct |
29 |
Correct |
11 ms |
1260 KB |
Output is correct |
30 |
Correct |
10 ms |
1108 KB |
Output is correct |
31 |
Correct |
11 ms |
1284 KB |
Output is correct |
32 |
Correct |
9 ms |
1236 KB |
Output is correct |
33 |
Correct |
11 ms |
1236 KB |
Output is correct |
34 |
Correct |
10 ms |
1192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
12 ms |
1364 KB |
Output is correct |
28 |
Correct |
10 ms |
1244 KB |
Output is correct |
29 |
Correct |
11 ms |
1260 KB |
Output is correct |
30 |
Correct |
10 ms |
1108 KB |
Output is correct |
31 |
Correct |
11 ms |
1284 KB |
Output is correct |
32 |
Correct |
9 ms |
1236 KB |
Output is correct |
33 |
Correct |
11 ms |
1236 KB |
Output is correct |
34 |
Correct |
10 ms |
1192 KB |
Output is correct |
35 |
Correct |
57 ms |
1312 KB |
Output is correct |
36 |
Correct |
53 ms |
1308 KB |
Output is correct |
37 |
Correct |
69 ms |
1284 KB |
Output is correct |
38 |
Correct |
63 ms |
1296 KB |
Output is correct |
39 |
Correct |
55 ms |
1312 KB |
Output is correct |
40 |
Correct |
36 ms |
1436 KB |
Output is correct |
41 |
Correct |
33 ms |
1364 KB |
Output is correct |
42 |
Correct |
30 ms |
1372 KB |
Output is correct |
43 |
Correct |
28 ms |
1364 KB |
Output is correct |
44 |
Correct |
40 ms |
1392 KB |
Output is correct |
45 |
Correct |
35 ms |
1396 KB |
Output is correct |
46 |
Correct |
30 ms |
1376 KB |
Output is correct |
47 |
Correct |
28 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
12 ms |
1364 KB |
Output is correct |
28 |
Correct |
10 ms |
1244 KB |
Output is correct |
29 |
Correct |
11 ms |
1260 KB |
Output is correct |
30 |
Correct |
10 ms |
1108 KB |
Output is correct |
31 |
Correct |
11 ms |
1284 KB |
Output is correct |
32 |
Correct |
9 ms |
1236 KB |
Output is correct |
33 |
Correct |
11 ms |
1236 KB |
Output is correct |
34 |
Correct |
10 ms |
1192 KB |
Output is correct |
35 |
Correct |
57 ms |
1312 KB |
Output is correct |
36 |
Correct |
53 ms |
1308 KB |
Output is correct |
37 |
Correct |
69 ms |
1284 KB |
Output is correct |
38 |
Correct |
63 ms |
1296 KB |
Output is correct |
39 |
Correct |
55 ms |
1312 KB |
Output is correct |
40 |
Correct |
36 ms |
1436 KB |
Output is correct |
41 |
Correct |
33 ms |
1364 KB |
Output is correct |
42 |
Correct |
30 ms |
1372 KB |
Output is correct |
43 |
Correct |
28 ms |
1364 KB |
Output is correct |
44 |
Correct |
40 ms |
1392 KB |
Output is correct |
45 |
Correct |
35 ms |
1396 KB |
Output is correct |
46 |
Correct |
30 ms |
1376 KB |
Output is correct |
47 |
Correct |
28 ms |
1364 KB |
Output is correct |
48 |
Correct |
773 ms |
11168 KB |
Output is correct |
49 |
Correct |
755 ms |
15588 KB |
Output is correct |
50 |
Correct |
772 ms |
15576 KB |
Output is correct |
51 |
Correct |
643 ms |
15128 KB |
Output is correct |
52 |
Correct |
505 ms |
13748 KB |
Output is correct |
53 |
Correct |
451 ms |
14792 KB |
Output is correct |
54 |
Correct |
349 ms |
13696 KB |
Output is correct |
55 |
Correct |
347 ms |
13768 KB |
Output is correct |
56 |
Correct |
304 ms |
13304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
12 ms |
1364 KB |
Output is correct |
28 |
Correct |
10 ms |
1244 KB |
Output is correct |
29 |
Correct |
11 ms |
1260 KB |
Output is correct |
30 |
Correct |
10 ms |
1108 KB |
Output is correct |
31 |
Correct |
11 ms |
1284 KB |
Output is correct |
32 |
Correct |
9 ms |
1236 KB |
Output is correct |
33 |
Correct |
11 ms |
1236 KB |
Output is correct |
34 |
Correct |
10 ms |
1192 KB |
Output is correct |
35 |
Correct |
57 ms |
1312 KB |
Output is correct |
36 |
Correct |
53 ms |
1308 KB |
Output is correct |
37 |
Correct |
69 ms |
1284 KB |
Output is correct |
38 |
Correct |
63 ms |
1296 KB |
Output is correct |
39 |
Correct |
55 ms |
1312 KB |
Output is correct |
40 |
Correct |
36 ms |
1436 KB |
Output is correct |
41 |
Correct |
33 ms |
1364 KB |
Output is correct |
42 |
Correct |
30 ms |
1372 KB |
Output is correct |
43 |
Correct |
28 ms |
1364 KB |
Output is correct |
44 |
Correct |
40 ms |
1392 KB |
Output is correct |
45 |
Correct |
35 ms |
1396 KB |
Output is correct |
46 |
Correct |
30 ms |
1376 KB |
Output is correct |
47 |
Correct |
28 ms |
1364 KB |
Output is correct |
48 |
Correct |
773 ms |
11168 KB |
Output is correct |
49 |
Correct |
755 ms |
15588 KB |
Output is correct |
50 |
Correct |
772 ms |
15576 KB |
Output is correct |
51 |
Correct |
643 ms |
15128 KB |
Output is correct |
52 |
Correct |
505 ms |
13748 KB |
Output is correct |
53 |
Correct |
451 ms |
14792 KB |
Output is correct |
54 |
Correct |
349 ms |
13696 KB |
Output is correct |
55 |
Correct |
347 ms |
13768 KB |
Output is correct |
56 |
Correct |
304 ms |
13304 KB |
Output is correct |
57 |
Execution timed out |
2554 ms |
120552 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |