# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205639 | Kastanda | Rope (JOI17_rope) | C++11 | 2595 ms | 2680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, A[N], dp[N][2][2];
inline void smin(int &a, int b) {a = min(a, b);}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++)
scanf("%d", &A[i]);
for (int c = 1; c <= m; c ++)
{
int Mn = 0;
for (int i = 1; i <= n; i ++)
if (A[i] != c) Mn ++;
for (int d = 1; d <= m; d ++)
if (d != c)
{
int cls[2] = {c, d}, cnt[2] = {0, 0};
memset(dp, 63, sizeof(dp));
for (int i = 1; i <= n; i ++)
{
cnt[0] += (A[i] != cls[0]);
cnt[1] += (A[i] != cls[1]);
dp[i][0][0] = dp[i][0][1] = cnt[0];
dp[i][1][0] = dp[i][1][1] = cnt[1];
}
for (int i = 1; i < n; i ++)
for (int w = 0; w <= 1; w ++)
for (int p = 0; p <= 1; p ++)
{
smin(dp[i + 1][w][!p], dp[i][w][p] + (A[i + 1] != cls[w]));
if (!p) smin(dp[i + 1][!w][1], dp[i][w][p] + (A[i + 1] != cls[!w]));
}
for (int w = 0; w <= 1; w ++)
for (int p = 0; p <= 1; p ++)
Mn = min(Mn, dp[n][w][p]);
}
printf("%d\n", Mn);
}
return 0;
}
Compilation message (stderr)
# | 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... |