# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
489152 |
2021-11-21T09:52:52 Z |
cheissmart |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
976 KB |
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emaplce_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
const int INF = 1e9 + 7, N = 1e6 + 7;
int c[N], ans[N];
void cmin(int& a, int b) {
a = min(a, b);
}
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++) {
cin >> c[i];
c[i]--;
}
auto go = [&] (int x, int y) {
int clr[] = {x, y};
auto cost = [&] (int i, int color) {
return int(clr[color] != c[i]);
};
// dp[cut 01][last][parity]
array<array<array<int, 2>, 2>, 2> dp;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
dp[i][j][k] = INF;
dp[0][0][1] = cost(0, 0);
dp[0][1][1] = cost(0, 1);
for(int idx = 1; idx < n; idx++) {
array<array<array<int, 2>, 2>, 2> ndp;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
ndp[i][j][k] = INF;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++) {
for(int l = 0; l < 2; l++) {
if(j == l)
cmin(ndp[i][l][k ^ 1], dp[i][j][k] + cost(idx, l));
else {
if(i && k) continue;
cmin(ndp[1][l][1], dp[i][j][k] + cost(idx, l));
}
}
}
swap(dp, ndp);
}
int mn = INF;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
for(int k = 0; k < 2; k++)
cmin(mn, dp[i][j][k]);
return mn;
};
for(int i = 0; i < m; i++)
ans[i] = INF;
for(int i = 0; i < m; i++)
for(int j = 0; j <= i; j++) {
int tt = go(i, j);
ans[i] = min(ans[i], tt);
ans[j] = min(ans[j], tt);
}
for(int i = 0; i < m; i++)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
320 KB |
Output is correct |
27 |
Correct |
234 ms |
912 KB |
Output is correct |
28 |
Correct |
47 ms |
912 KB |
Output is correct |
29 |
Correct |
191 ms |
848 KB |
Output is correct |
30 |
Correct |
91 ms |
848 KB |
Output is correct |
31 |
Correct |
227 ms |
852 KB |
Output is correct |
32 |
Correct |
48 ms |
964 KB |
Output is correct |
33 |
Correct |
189 ms |
900 KB |
Output is correct |
34 |
Correct |
68 ms |
900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
320 KB |
Output is correct |
27 |
Correct |
234 ms |
912 KB |
Output is correct |
28 |
Correct |
47 ms |
912 KB |
Output is correct |
29 |
Correct |
191 ms |
848 KB |
Output is correct |
30 |
Correct |
91 ms |
848 KB |
Output is correct |
31 |
Correct |
227 ms |
852 KB |
Output is correct |
32 |
Correct |
48 ms |
964 KB |
Output is correct |
33 |
Correct |
189 ms |
900 KB |
Output is correct |
34 |
Correct |
68 ms |
900 KB |
Output is correct |
35 |
Execution timed out |
2576 ms |
976 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
320 KB |
Output is correct |
27 |
Correct |
234 ms |
912 KB |
Output is correct |
28 |
Correct |
47 ms |
912 KB |
Output is correct |
29 |
Correct |
191 ms |
848 KB |
Output is correct |
30 |
Correct |
91 ms |
848 KB |
Output is correct |
31 |
Correct |
227 ms |
852 KB |
Output is correct |
32 |
Correct |
48 ms |
964 KB |
Output is correct |
33 |
Correct |
189 ms |
900 KB |
Output is correct |
34 |
Correct |
68 ms |
900 KB |
Output is correct |
35 |
Execution timed out |
2576 ms |
976 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
0 ms |
336 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
320 KB |
Output is correct |
27 |
Correct |
234 ms |
912 KB |
Output is correct |
28 |
Correct |
47 ms |
912 KB |
Output is correct |
29 |
Correct |
191 ms |
848 KB |
Output is correct |
30 |
Correct |
91 ms |
848 KB |
Output is correct |
31 |
Correct |
227 ms |
852 KB |
Output is correct |
32 |
Correct |
48 ms |
964 KB |
Output is correct |
33 |
Correct |
189 ms |
900 KB |
Output is correct |
34 |
Correct |
68 ms |
900 KB |
Output is correct |
35 |
Execution timed out |
2576 ms |
976 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |