#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[11];
int solve(int s, int e, int x, int y){
int ans = 0;
for(int i=s+1; i<=e; i+=2){
ans += min((a[i-1] != x) + (a[i] != x), (a[i-1] != y) + (a[i] != y));
}
return ans;
}
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));
if(n % 2 == 0){
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
int x = solve(1, n, i, j);
int y = solve(2, n-1, i, j) + (a[1] != i && a[1] != j) + (a[n] != i && a[n] != j);
ans[i] = min({ans[i], x, y});
ans[j] = min({ans[j], x, y});
}
}
}
else{
for(int i=1; i<=m; i++){
for(int j=1; j<=i; j++){
int x = solve(1, n-1, i, j) + (a[n] != i && a[n] != j);
int y = solve(2, n, i, j) + (a[1] != i && a[1] != j);
ans[i] = min({ans[i], x, y});
ans[j] = min({ans[j], x, y});
}
}
}
for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:19: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:21:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Correct |
0 ms |
5924 KB |
Output is correct |
5 |
Correct |
0 ms |
5924 KB |
Output is correct |
6 |
Correct |
0 ms |
5924 KB |
Output is correct |
7 |
Correct |
0 ms |
5924 KB |
Output is correct |
8 |
Correct |
0 ms |
5924 KB |
Output is correct |
9 |
Correct |
0 ms |
5924 KB |
Output is correct |
10 |
Correct |
0 ms |
5924 KB |
Output is correct |
11 |
Correct |
0 ms |
5924 KB |
Output is correct |
12 |
Correct |
0 ms |
5924 KB |
Output is correct |
13 |
Correct |
0 ms |
5924 KB |
Output is correct |
14 |
Correct |
0 ms |
5924 KB |
Output is correct |
15 |
Correct |
0 ms |
5924 KB |
Output is correct |
16 |
Correct |
0 ms |
5924 KB |
Output is correct |
17 |
Correct |
0 ms |
5924 KB |
Output is correct |
18 |
Correct |
0 ms |
5924 KB |
Output is correct |
19 |
Correct |
0 ms |
5924 KB |
Output is correct |
20 |
Correct |
0 ms |
5924 KB |
Output is correct |
21 |
Correct |
0 ms |
5924 KB |
Output is correct |
22 |
Correct |
0 ms |
5924 KB |
Output is correct |
23 |
Correct |
0 ms |
5924 KB |
Output is correct |
24 |
Correct |
0 ms |
5924 KB |
Output is correct |
25 |
Correct |
0 ms |
5924 KB |
Output is correct |
26 |
Correct |
0 ms |
5924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Correct |
0 ms |
5924 KB |
Output is correct |
5 |
Correct |
0 ms |
5924 KB |
Output is correct |
6 |
Correct |
0 ms |
5924 KB |
Output is correct |
7 |
Correct |
0 ms |
5924 KB |
Output is correct |
8 |
Correct |
0 ms |
5924 KB |
Output is correct |
9 |
Correct |
0 ms |
5924 KB |
Output is correct |
10 |
Correct |
0 ms |
5924 KB |
Output is correct |
11 |
Correct |
0 ms |
5924 KB |
Output is correct |
12 |
Correct |
0 ms |
5924 KB |
Output is correct |
13 |
Correct |
0 ms |
5924 KB |
Output is correct |
14 |
Correct |
0 ms |
5924 KB |
Output is correct |
15 |
Correct |
0 ms |
5924 KB |
Output is correct |
16 |
Correct |
0 ms |
5924 KB |
Output is correct |
17 |
Correct |
0 ms |
5924 KB |
Output is correct |
18 |
Correct |
0 ms |
5924 KB |
Output is correct |
19 |
Correct |
0 ms |
5924 KB |
Output is correct |
20 |
Correct |
0 ms |
5924 KB |
Output is correct |
21 |
Correct |
0 ms |
5924 KB |
Output is correct |
22 |
Correct |
0 ms |
5924 KB |
Output is correct |
23 |
Correct |
0 ms |
5924 KB |
Output is correct |
24 |
Correct |
0 ms |
5924 KB |
Output is correct |
25 |
Correct |
0 ms |
5924 KB |
Output is correct |
26 |
Correct |
0 ms |
5924 KB |
Output is correct |
27 |
Correct |
23 ms |
5924 KB |
Output is correct |
28 |
Correct |
9 ms |
5924 KB |
Output is correct |
29 |
Correct |
19 ms |
5924 KB |
Output is correct |
30 |
Correct |
13 ms |
5924 KB |
Output is correct |
31 |
Correct |
29 ms |
5924 KB |
Output is correct |
32 |
Correct |
13 ms |
5924 KB |
Output is correct |
33 |
Correct |
26 ms |
5924 KB |
Output is correct |
34 |
Correct |
13 ms |
5924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Correct |
0 ms |
5924 KB |
Output is correct |
5 |
Correct |
0 ms |
5924 KB |
Output is correct |
6 |
Correct |
0 ms |
5924 KB |
Output is correct |
7 |
Correct |
0 ms |
5924 KB |
Output is correct |
8 |
Correct |
0 ms |
5924 KB |
Output is correct |
9 |
Correct |
0 ms |
5924 KB |
Output is correct |
10 |
Correct |
0 ms |
5924 KB |
Output is correct |
11 |
Correct |
0 ms |
5924 KB |
Output is correct |
12 |
Correct |
0 ms |
5924 KB |
Output is correct |
13 |
Correct |
0 ms |
5924 KB |
Output is correct |
14 |
Correct |
0 ms |
5924 KB |
Output is correct |
15 |
Correct |
0 ms |
5924 KB |
Output is correct |
16 |
Correct |
0 ms |
5924 KB |
Output is correct |
17 |
Correct |
0 ms |
5924 KB |
Output is correct |
18 |
Correct |
0 ms |
5924 KB |
Output is correct |
19 |
Correct |
0 ms |
5924 KB |
Output is correct |
20 |
Correct |
0 ms |
5924 KB |
Output is correct |
21 |
Correct |
0 ms |
5924 KB |
Output is correct |
22 |
Correct |
0 ms |
5924 KB |
Output is correct |
23 |
Correct |
0 ms |
5924 KB |
Output is correct |
24 |
Correct |
0 ms |
5924 KB |
Output is correct |
25 |
Correct |
0 ms |
5924 KB |
Output is correct |
26 |
Correct |
0 ms |
5924 KB |
Output is correct |
27 |
Correct |
23 ms |
5924 KB |
Output is correct |
28 |
Correct |
9 ms |
5924 KB |
Output is correct |
29 |
Correct |
19 ms |
5924 KB |
Output is correct |
30 |
Correct |
13 ms |
5924 KB |
Output is correct |
31 |
Correct |
29 ms |
5924 KB |
Output is correct |
32 |
Correct |
13 ms |
5924 KB |
Output is correct |
33 |
Correct |
26 ms |
5924 KB |
Output is correct |
34 |
Correct |
13 ms |
5924 KB |
Output is correct |
35 |
Incorrect |
9 ms |
5924 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Correct |
0 ms |
5924 KB |
Output is correct |
5 |
Correct |
0 ms |
5924 KB |
Output is correct |
6 |
Correct |
0 ms |
5924 KB |
Output is correct |
7 |
Correct |
0 ms |
5924 KB |
Output is correct |
8 |
Correct |
0 ms |
5924 KB |
Output is correct |
9 |
Correct |
0 ms |
5924 KB |
Output is correct |
10 |
Correct |
0 ms |
5924 KB |
Output is correct |
11 |
Correct |
0 ms |
5924 KB |
Output is correct |
12 |
Correct |
0 ms |
5924 KB |
Output is correct |
13 |
Correct |
0 ms |
5924 KB |
Output is correct |
14 |
Correct |
0 ms |
5924 KB |
Output is correct |
15 |
Correct |
0 ms |
5924 KB |
Output is correct |
16 |
Correct |
0 ms |
5924 KB |
Output is correct |
17 |
Correct |
0 ms |
5924 KB |
Output is correct |
18 |
Correct |
0 ms |
5924 KB |
Output is correct |
19 |
Correct |
0 ms |
5924 KB |
Output is correct |
20 |
Correct |
0 ms |
5924 KB |
Output is correct |
21 |
Correct |
0 ms |
5924 KB |
Output is correct |
22 |
Correct |
0 ms |
5924 KB |
Output is correct |
23 |
Correct |
0 ms |
5924 KB |
Output is correct |
24 |
Correct |
0 ms |
5924 KB |
Output is correct |
25 |
Correct |
0 ms |
5924 KB |
Output is correct |
26 |
Correct |
0 ms |
5924 KB |
Output is correct |
27 |
Correct |
23 ms |
5924 KB |
Output is correct |
28 |
Correct |
9 ms |
5924 KB |
Output is correct |
29 |
Correct |
19 ms |
5924 KB |
Output is correct |
30 |
Correct |
13 ms |
5924 KB |
Output is correct |
31 |
Correct |
29 ms |
5924 KB |
Output is correct |
32 |
Correct |
13 ms |
5924 KB |
Output is correct |
33 |
Correct |
26 ms |
5924 KB |
Output is correct |
34 |
Correct |
13 ms |
5924 KB |
Output is correct |
35 |
Incorrect |
9 ms |
5924 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Correct |
0 ms |
5924 KB |
Output is correct |
5 |
Correct |
0 ms |
5924 KB |
Output is correct |
6 |
Correct |
0 ms |
5924 KB |
Output is correct |
7 |
Correct |
0 ms |
5924 KB |
Output is correct |
8 |
Correct |
0 ms |
5924 KB |
Output is correct |
9 |
Correct |
0 ms |
5924 KB |
Output is correct |
10 |
Correct |
0 ms |
5924 KB |
Output is correct |
11 |
Correct |
0 ms |
5924 KB |
Output is correct |
12 |
Correct |
0 ms |
5924 KB |
Output is correct |
13 |
Correct |
0 ms |
5924 KB |
Output is correct |
14 |
Correct |
0 ms |
5924 KB |
Output is correct |
15 |
Correct |
0 ms |
5924 KB |
Output is correct |
16 |
Correct |
0 ms |
5924 KB |
Output is correct |
17 |
Correct |
0 ms |
5924 KB |
Output is correct |
18 |
Correct |
0 ms |
5924 KB |
Output is correct |
19 |
Correct |
0 ms |
5924 KB |
Output is correct |
20 |
Correct |
0 ms |
5924 KB |
Output is correct |
21 |
Correct |
0 ms |
5924 KB |
Output is correct |
22 |
Correct |
0 ms |
5924 KB |
Output is correct |
23 |
Correct |
0 ms |
5924 KB |
Output is correct |
24 |
Correct |
0 ms |
5924 KB |
Output is correct |
25 |
Correct |
0 ms |
5924 KB |
Output is correct |
26 |
Correct |
0 ms |
5924 KB |
Output is correct |
27 |
Correct |
23 ms |
5924 KB |
Output is correct |
28 |
Correct |
9 ms |
5924 KB |
Output is correct |
29 |
Correct |
19 ms |
5924 KB |
Output is correct |
30 |
Correct |
13 ms |
5924 KB |
Output is correct |
31 |
Correct |
29 ms |
5924 KB |
Output is correct |
32 |
Correct |
13 ms |
5924 KB |
Output is correct |
33 |
Correct |
26 ms |
5924 KB |
Output is correct |
34 |
Correct |
13 ms |
5924 KB |
Output is correct |
35 |
Incorrect |
9 ms |
5924 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |