Submission #20925

# Submission time Handle Problem Language Result Execution time Memory
20925 2017-03-21T16:55:22 Z gs14004 Rope (JOI17_rope) C++11
45 / 100
29 ms 21552 KB
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;

int n, m, a[1000005];
int ans[1000005];
int dp[1000005][3];

int solve(int x, int y){
	for(int i=1; i<=n; i++){
		dp[i][0] = dp[i-1][1] + (a[i] != x);
		dp[i][1] = min(dp[i-1][0] + (a[i] != x), dp[i-1][2] + (a[i] != y));
		dp[i][2] = dp[i-1][1] + (a[i] != y);
	}
	return min({dp[n][0], dp[n][1], dp[n][2]});
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
	}
	if(m > 10) return 0;
	memset(ans, 0x3f, sizeof(ans));
	for(int i=1; i<=m; i++){
		for(int j=1; j<=i; j++){
			int x = solve(i, j);
			ans[i] = min(ans[i], x);
			ans[j] = min(ans[j], x);
		}
	}
	for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:21:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
                      ^
rope.cpp:23:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^

# Verdict Execution time Memory Grader output
1 Correct 0 ms 21552 KB Output is correct
2 Correct 0 ms 21552 KB Output is correct
3 Correct 0 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 0 ms 21552 KB Output is correct
6 Correct 0 ms 21552 KB Output is correct
7 Correct 0 ms 21552 KB Output is correct
8 Correct 0 ms 21552 KB Output is correct
9 Correct 0 ms 21552 KB Output is correct
10 Correct 0 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 0 ms 21552 KB Output is correct
13 Correct 0 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 0 ms 21552 KB Output is correct
16 Correct 3 ms 21552 KB Output is correct
17 Correct 0 ms 21552 KB Output is correct
18 Correct 0 ms 21552 KB Output is correct
19 Correct 0 ms 21552 KB Output is correct
20 Correct 0 ms 21552 KB Output is correct
21 Correct 3 ms 21552 KB Output is correct
22 Correct 3 ms 21552 KB Output is correct
23 Correct 0 ms 21552 KB Output is correct
24 Correct 0 ms 21552 KB Output is correct
25 Correct 0 ms 21552 KB Output is correct
26 Correct 3 ms 21552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21552 KB Output is correct
2 Correct 0 ms 21552 KB Output is correct
3 Correct 0 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 0 ms 21552 KB Output is correct
6 Correct 0 ms 21552 KB Output is correct
7 Correct 0 ms 21552 KB Output is correct
8 Correct 0 ms 21552 KB Output is correct
9 Correct 0 ms 21552 KB Output is correct
10 Correct 0 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 0 ms 21552 KB Output is correct
13 Correct 0 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 0 ms 21552 KB Output is correct
16 Correct 3 ms 21552 KB Output is correct
17 Correct 0 ms 21552 KB Output is correct
18 Correct 0 ms 21552 KB Output is correct
19 Correct 0 ms 21552 KB Output is correct
20 Correct 0 ms 21552 KB Output is correct
21 Correct 3 ms 21552 KB Output is correct
22 Correct 3 ms 21552 KB Output is correct
23 Correct 0 ms 21552 KB Output is correct
24 Correct 0 ms 21552 KB Output is correct
25 Correct 0 ms 21552 KB Output is correct
26 Correct 3 ms 21552 KB Output is correct
27 Correct 29 ms 21552 KB Output is correct
28 Correct 16 ms 21552 KB Output is correct
29 Correct 26 ms 21552 KB Output is correct
30 Correct 16 ms 21552 KB Output is correct
31 Correct 29 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 26 ms 21552 KB Output is correct
34 Correct 23 ms 21552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21552 KB Output is correct
2 Correct 0 ms 21552 KB Output is correct
3 Correct 0 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 0 ms 21552 KB Output is correct
6 Correct 0 ms 21552 KB Output is correct
7 Correct 0 ms 21552 KB Output is correct
8 Correct 0 ms 21552 KB Output is correct
9 Correct 0 ms 21552 KB Output is correct
10 Correct 0 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 0 ms 21552 KB Output is correct
13 Correct 0 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 0 ms 21552 KB Output is correct
16 Correct 3 ms 21552 KB Output is correct
17 Correct 0 ms 21552 KB Output is correct
18 Correct 0 ms 21552 KB Output is correct
19 Correct 0 ms 21552 KB Output is correct
20 Correct 0 ms 21552 KB Output is correct
21 Correct 3 ms 21552 KB Output is correct
22 Correct 3 ms 21552 KB Output is correct
23 Correct 0 ms 21552 KB Output is correct
24 Correct 0 ms 21552 KB Output is correct
25 Correct 0 ms 21552 KB Output is correct
26 Correct 3 ms 21552 KB Output is correct
27 Correct 29 ms 21552 KB Output is correct
28 Correct 16 ms 21552 KB Output is correct
29 Correct 26 ms 21552 KB Output is correct
30 Correct 16 ms 21552 KB Output is correct
31 Correct 29 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 26 ms 21552 KB Output is correct
34 Correct 23 ms 21552 KB Output is correct
35 Incorrect 13 ms 21552 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21552 KB Output is correct
2 Correct 0 ms 21552 KB Output is correct
3 Correct 0 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 0 ms 21552 KB Output is correct
6 Correct 0 ms 21552 KB Output is correct
7 Correct 0 ms 21552 KB Output is correct
8 Correct 0 ms 21552 KB Output is correct
9 Correct 0 ms 21552 KB Output is correct
10 Correct 0 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 0 ms 21552 KB Output is correct
13 Correct 0 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 0 ms 21552 KB Output is correct
16 Correct 3 ms 21552 KB Output is correct
17 Correct 0 ms 21552 KB Output is correct
18 Correct 0 ms 21552 KB Output is correct
19 Correct 0 ms 21552 KB Output is correct
20 Correct 0 ms 21552 KB Output is correct
21 Correct 3 ms 21552 KB Output is correct
22 Correct 3 ms 21552 KB Output is correct
23 Correct 0 ms 21552 KB Output is correct
24 Correct 0 ms 21552 KB Output is correct
25 Correct 0 ms 21552 KB Output is correct
26 Correct 3 ms 21552 KB Output is correct
27 Correct 29 ms 21552 KB Output is correct
28 Correct 16 ms 21552 KB Output is correct
29 Correct 26 ms 21552 KB Output is correct
30 Correct 16 ms 21552 KB Output is correct
31 Correct 29 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 26 ms 21552 KB Output is correct
34 Correct 23 ms 21552 KB Output is correct
35 Incorrect 13 ms 21552 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21552 KB Output is correct
2 Correct 0 ms 21552 KB Output is correct
3 Correct 0 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 0 ms 21552 KB Output is correct
6 Correct 0 ms 21552 KB Output is correct
7 Correct 0 ms 21552 KB Output is correct
8 Correct 0 ms 21552 KB Output is correct
9 Correct 0 ms 21552 KB Output is correct
10 Correct 0 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 0 ms 21552 KB Output is correct
13 Correct 0 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 0 ms 21552 KB Output is correct
16 Correct 3 ms 21552 KB Output is correct
17 Correct 0 ms 21552 KB Output is correct
18 Correct 0 ms 21552 KB Output is correct
19 Correct 0 ms 21552 KB Output is correct
20 Correct 0 ms 21552 KB Output is correct
21 Correct 3 ms 21552 KB Output is correct
22 Correct 3 ms 21552 KB Output is correct
23 Correct 0 ms 21552 KB Output is correct
24 Correct 0 ms 21552 KB Output is correct
25 Correct 0 ms 21552 KB Output is correct
26 Correct 3 ms 21552 KB Output is correct
27 Correct 29 ms 21552 KB Output is correct
28 Correct 16 ms 21552 KB Output is correct
29 Correct 26 ms 21552 KB Output is correct
30 Correct 16 ms 21552 KB Output is correct
31 Correct 29 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 26 ms 21552 KB Output is correct
34 Correct 23 ms 21552 KB Output is correct
35 Incorrect 13 ms 21552 KB Output isn't correct
36 Halted 0 ms 0 KB -