# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
598794 |
2022-07-19T05:23:47 Z |
piOOE |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
1860 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100002, M = 10;
int a[N], ans[M];
int pref[N], suf[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(ans, 0x3f, sizeof(ans));
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
--a[i];
}
for (int c1 = 0; c1 < m; ++c1) {
for (int c2 = 0; c2 < m; ++c2) {
int c[2] = {c1, c2};
pref[1] = min(c[0] != a[1], c[1] != a[1]);
for (int i = 2; i <= n; ++i) {
pref[i] = min((c[0] != a[i - 1]) + (c[0] != a[i]), (c[1] != a[i - 1]) + (c[1] != a[i])) + pref[i - 2];
}
suf[n] = min(c[0] != a[n], c[1] != a[n]);
for (int i = n - 1; i > 0; --i) {
suf[i] = min((c[0] != a[i + 1]) + (c[0] != a[i]), (c[1] != a[i + 1]) + (c[1] != a[i])) + suf[i + 2];
}
for (int i = 1; i <= n - 1; ++i) {
int now = (i > 1 ? a[i - 1] != c[0] : 0) + pref[i - 2] + (i + 2 <= n ? a[i + 2] != c[1] : 0) + suf[i + 3] +
(a[i] != c[0]) + (a[i + 1] != c[1]);
ans[c1] = min(ans[c1], now);
ans[c2] = min(ans[c2], now);
}
}
}
for (int i = 0; i < m; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
95 ms |
1680 KB |
Output is correct |
28 |
Correct |
22 ms |
1620 KB |
Output is correct |
29 |
Correct |
72 ms |
1628 KB |
Output is correct |
30 |
Correct |
28 ms |
1592 KB |
Output is correct |
31 |
Correct |
86 ms |
1620 KB |
Output is correct |
32 |
Correct |
19 ms |
1620 KB |
Output is correct |
33 |
Correct |
83 ms |
1676 KB |
Output is correct |
34 |
Correct |
33 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
95 ms |
1680 KB |
Output is correct |
28 |
Correct |
22 ms |
1620 KB |
Output is correct |
29 |
Correct |
72 ms |
1628 KB |
Output is correct |
30 |
Correct |
28 ms |
1592 KB |
Output is correct |
31 |
Correct |
86 ms |
1620 KB |
Output is correct |
32 |
Correct |
19 ms |
1620 KB |
Output is correct |
33 |
Correct |
83 ms |
1676 KB |
Output is correct |
34 |
Correct |
33 ms |
1620 KB |
Output is correct |
35 |
Execution timed out |
2578 ms |
1860 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
95 ms |
1680 KB |
Output is correct |
28 |
Correct |
22 ms |
1620 KB |
Output is correct |
29 |
Correct |
72 ms |
1628 KB |
Output is correct |
30 |
Correct |
28 ms |
1592 KB |
Output is correct |
31 |
Correct |
86 ms |
1620 KB |
Output is correct |
32 |
Correct |
19 ms |
1620 KB |
Output is correct |
33 |
Correct |
83 ms |
1676 KB |
Output is correct |
34 |
Correct |
33 ms |
1620 KB |
Output is correct |
35 |
Execution timed out |
2578 ms |
1860 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
95 ms |
1680 KB |
Output is correct |
28 |
Correct |
22 ms |
1620 KB |
Output is correct |
29 |
Correct |
72 ms |
1628 KB |
Output is correct |
30 |
Correct |
28 ms |
1592 KB |
Output is correct |
31 |
Correct |
86 ms |
1620 KB |
Output is correct |
32 |
Correct |
19 ms |
1620 KB |
Output is correct |
33 |
Correct |
83 ms |
1676 KB |
Output is correct |
34 |
Correct |
33 ms |
1620 KB |
Output is correct |
35 |
Execution timed out |
2578 ms |
1860 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |