# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397694 | ChrisT | Group Photo (JOI21_ho_t3) | C++17 | 1 ms | 332 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.
#include <bits/stdc++.h>
using namespace std;
const int MN = 5e3 + 5;
int dp[MN], f[MN][MN], a[MN], stopAt[MN];
int main () {
int n; scanf ("%d",&n);
for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
if (a[i] < a[j]) {
f[1][a[j]]++; f[a[i]+1][a[j]]--;
} else {
f[a[j]+1][1]++; f[a[i]+1][1]--;
}
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[i][j] += f[i-1][j] + f[i][j-1] - f[i-1][j-1];
for (int i = 1; i <= n; i++) {
dp[i] = 1e9;
for (int j = i; j >= 1; j--) dp[i] = min(dp[i],dp[j-1]+f[j][i]);
}
printf ("%d\n",dp[n]);
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... |