# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
598720 |
2022-07-18T19:33:32 Z |
piOOE |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
4156 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100000, M = 10;
int a[N], ans[M];
int pref[2][2][N], suf[2][2][N]; // {first or second, left or right}
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];
}
for (int c1 = 0; c1 < m; ++c1) {
for (int c2 = 0; c2 < m; ++c2) {
memset(pref, 0x3f, sizeof(pref)), memset(suf, 0x3f, sizeof(suf));
int c[2] = {c1, c2};
pref[0][0][0] = pref[0][1][0] = a[0] != c[0];
pref[1][0][0] = pref[1][1][0] = a[0] != c[1];
for (int i = 1; i < n; ++i) {
pref[1][1][i] = (a[i] != c[1]) + pref[1][0][i - 1];
pref[1][0][i] = (a[i] != c[1]) + min(pref[1][1][i - 1], pref[0][0][i - 1]);
pref[0][1][i] = (a[i] != c[0]) + min(pref[0][0][i - 1], pref[1][1][i - 1]);
pref[0][0][i] = (a[i] != c[0]) + pref[0][1][i - 1];
}
suf[0][0][n - 1] = suf[0][1][n - 1] = a[n - 1] != c[0];
suf[1][0][n - 1] = suf[1][1][n - 1] = a[n - 1] != c[1];
for (int i = n - 2; i > -1; --i) {
suf[1][1][i] = (a[i] != c[1]) + suf[1][0][i + 1];
suf[1][0][i] = (a[i] != c[1]) + min(suf[1][1][i + 1], suf[0][0][i + 1]);
suf[0][1][i] = (a[i] != c[0]) + min(suf[0][0][i + 1], suf[1][1][i + 1]);
suf[0][0][i] = (a[i] != c[0]) + suf[0][1][i + 1];
}
for (int i = 0; i < n - 1; ++i) {
int now = pref[0][0][i] + suf[1][1][i + 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 |
9 ms |
3412 KB |
Output is correct |
2 |
Correct |
11 ms |
3456 KB |
Output is correct |
3 |
Correct |
10 ms |
3452 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
9 ms |
3460 KB |
Output is correct |
7 |
Correct |
7 ms |
3412 KB |
Output is correct |
8 |
Correct |
6 ms |
3452 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
14 ms |
3524 KB |
Output is correct |
12 |
Correct |
10 ms |
3412 KB |
Output is correct |
13 |
Correct |
7 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
8 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3412 KB |
Output is correct |
2 |
Correct |
11 ms |
3456 KB |
Output is correct |
3 |
Correct |
10 ms |
3452 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
9 ms |
3460 KB |
Output is correct |
7 |
Correct |
7 ms |
3412 KB |
Output is correct |
8 |
Correct |
6 ms |
3452 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
14 ms |
3524 KB |
Output is correct |
12 |
Correct |
10 ms |
3412 KB |
Output is correct |
13 |
Correct |
7 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
8 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3348 KB |
Output is correct |
27 |
Correct |
142 ms |
4028 KB |
Output is correct |
28 |
Correct |
30 ms |
4020 KB |
Output is correct |
29 |
Correct |
102 ms |
4020 KB |
Output is correct |
30 |
Correct |
48 ms |
4020 KB |
Output is correct |
31 |
Correct |
130 ms |
4032 KB |
Output is correct |
32 |
Correct |
29 ms |
3932 KB |
Output is correct |
33 |
Correct |
106 ms |
4044 KB |
Output is correct |
34 |
Correct |
45 ms |
4024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3412 KB |
Output is correct |
2 |
Correct |
11 ms |
3456 KB |
Output is correct |
3 |
Correct |
10 ms |
3452 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
9 ms |
3460 KB |
Output is correct |
7 |
Correct |
7 ms |
3412 KB |
Output is correct |
8 |
Correct |
6 ms |
3452 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
14 ms |
3524 KB |
Output is correct |
12 |
Correct |
10 ms |
3412 KB |
Output is correct |
13 |
Correct |
7 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
8 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3348 KB |
Output is correct |
27 |
Correct |
142 ms |
4028 KB |
Output is correct |
28 |
Correct |
30 ms |
4020 KB |
Output is correct |
29 |
Correct |
102 ms |
4020 KB |
Output is correct |
30 |
Correct |
48 ms |
4020 KB |
Output is correct |
31 |
Correct |
130 ms |
4032 KB |
Output is correct |
32 |
Correct |
29 ms |
3932 KB |
Output is correct |
33 |
Correct |
106 ms |
4044 KB |
Output is correct |
34 |
Correct |
45 ms |
4024 KB |
Output is correct |
35 |
Execution timed out |
2549 ms |
4156 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3412 KB |
Output is correct |
2 |
Correct |
11 ms |
3456 KB |
Output is correct |
3 |
Correct |
10 ms |
3452 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
9 ms |
3460 KB |
Output is correct |
7 |
Correct |
7 ms |
3412 KB |
Output is correct |
8 |
Correct |
6 ms |
3452 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
14 ms |
3524 KB |
Output is correct |
12 |
Correct |
10 ms |
3412 KB |
Output is correct |
13 |
Correct |
7 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
8 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3348 KB |
Output is correct |
27 |
Correct |
142 ms |
4028 KB |
Output is correct |
28 |
Correct |
30 ms |
4020 KB |
Output is correct |
29 |
Correct |
102 ms |
4020 KB |
Output is correct |
30 |
Correct |
48 ms |
4020 KB |
Output is correct |
31 |
Correct |
130 ms |
4032 KB |
Output is correct |
32 |
Correct |
29 ms |
3932 KB |
Output is correct |
33 |
Correct |
106 ms |
4044 KB |
Output is correct |
34 |
Correct |
45 ms |
4024 KB |
Output is correct |
35 |
Execution timed out |
2549 ms |
4156 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3412 KB |
Output is correct |
2 |
Correct |
11 ms |
3456 KB |
Output is correct |
3 |
Correct |
10 ms |
3452 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
3 ms |
3412 KB |
Output is correct |
6 |
Correct |
9 ms |
3460 KB |
Output is correct |
7 |
Correct |
7 ms |
3412 KB |
Output is correct |
8 |
Correct |
6 ms |
3452 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
14 ms |
3524 KB |
Output is correct |
12 |
Correct |
10 ms |
3412 KB |
Output is correct |
13 |
Correct |
7 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
8 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3412 KB |
Output is correct |
19 |
Correct |
4 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
3 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3348 KB |
Output is correct |
27 |
Correct |
142 ms |
4028 KB |
Output is correct |
28 |
Correct |
30 ms |
4020 KB |
Output is correct |
29 |
Correct |
102 ms |
4020 KB |
Output is correct |
30 |
Correct |
48 ms |
4020 KB |
Output is correct |
31 |
Correct |
130 ms |
4032 KB |
Output is correct |
32 |
Correct |
29 ms |
3932 KB |
Output is correct |
33 |
Correct |
106 ms |
4044 KB |
Output is correct |
34 |
Correct |
45 ms |
4024 KB |
Output is correct |
35 |
Execution timed out |
2549 ms |
4156 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |