# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
254613 |
2020-07-30T10:34:46 Z |
pit4h |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
1152 KB |
#include<bits/stdc++.h>
using namespace std;
int solve(int c1, int c2, vector<int>& a, int m) {
int n = a.size();
vector<vector<int>> dp(3, vector<int>(3, n));
dp[0][0] = 0;
for(int i=0; i<n; ++i) {
vector<vector<int>> ndp(3, vector<int>(3, n));
ndp[2][0] = min(dp[2][0], dp[0][0]) + ((a[i]==c1)?0:1);
ndp[2][1] = min(dp[2][2], dp[0][2]) + ((a[i]==c1)?0:1);
ndp[2][2] = min(dp[2][1], dp[0][1]) + ((a[i]==c1)?0:1);
ndp[0][2] = min(dp[0][2], dp[0][0]) + ((a[i]==c2)?0:1);
ndp[1][2] = min(dp[2][2], dp[2][0]) + ((a[i]==c2)?0:1);
ndp[2][2] = min(ndp[2][2], min(dp[1][2], dp[1][0]) + ((a[i]==c2)?0:1));
//cerr<<"iter "<<i<<' '<<a[i]<<' '<<dp[2][1]+((a[i]==c1)?0:1)<<'\n';
dp = ndp;
/*for(int x=0; x<=2; ++x) {
for(int y=0; y<=2; ++y) {
cerr<<dp[x][y]<<' ';
}
cerr<<'\n';
}
cerr<<'\n';*/
}
int res = n;
for(int i=0; i<=2; ++i) {
for(int j=0; j<=2; ++j) {
res = min(res, dp[i][j]);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
vector<int> a(n);
for(int i=0; i<n; ++i) {
cin>>a[i];
}
for(int i=1; i<=m; ++i) {
int ans = n;
for(int j=1; j<=m; ++j) {
ans = min(ans, solve(i, j, a, m));
//cerr<<"solve "<<i<<' '<<j<<": "<<solve(i, j, a, m)<<'\n';
}
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
2143 ms |
896 KB |
Output is correct |
28 |
Correct |
319 ms |
896 KB |
Output is correct |
29 |
Correct |
1594 ms |
896 KB |
Output is correct |
30 |
Correct |
487 ms |
896 KB |
Output is correct |
31 |
Correct |
1926 ms |
896 KB |
Output is correct |
32 |
Correct |
324 ms |
896 KB |
Output is correct |
33 |
Correct |
1608 ms |
896 KB |
Output is correct |
34 |
Correct |
500 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
2143 ms |
896 KB |
Output is correct |
28 |
Correct |
319 ms |
896 KB |
Output is correct |
29 |
Correct |
1594 ms |
896 KB |
Output is correct |
30 |
Correct |
487 ms |
896 KB |
Output is correct |
31 |
Correct |
1926 ms |
896 KB |
Output is correct |
32 |
Correct |
324 ms |
896 KB |
Output is correct |
33 |
Correct |
1608 ms |
896 KB |
Output is correct |
34 |
Correct |
500 ms |
896 KB |
Output is correct |
35 |
Execution timed out |
2570 ms |
1152 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
2143 ms |
896 KB |
Output is correct |
28 |
Correct |
319 ms |
896 KB |
Output is correct |
29 |
Correct |
1594 ms |
896 KB |
Output is correct |
30 |
Correct |
487 ms |
896 KB |
Output is correct |
31 |
Correct |
1926 ms |
896 KB |
Output is correct |
32 |
Correct |
324 ms |
896 KB |
Output is correct |
33 |
Correct |
1608 ms |
896 KB |
Output is correct |
34 |
Correct |
500 ms |
896 KB |
Output is correct |
35 |
Execution timed out |
2570 ms |
1152 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
2143 ms |
896 KB |
Output is correct |
28 |
Correct |
319 ms |
896 KB |
Output is correct |
29 |
Correct |
1594 ms |
896 KB |
Output is correct |
30 |
Correct |
487 ms |
896 KB |
Output is correct |
31 |
Correct |
1926 ms |
896 KB |
Output is correct |
32 |
Correct |
324 ms |
896 KB |
Output is correct |
33 |
Correct |
1608 ms |
896 KB |
Output is correct |
34 |
Correct |
500 ms |
896 KB |
Output is correct |
35 |
Execution timed out |
2570 ms |
1152 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |