This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |