# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092368 | ortsac | Group Photo (JOI21_ho_t3) | C++17 | 0 ms | 436 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 INF = 0x3f3f3f3f;
const int MAXN = 5005;
int dp[MAXN];
int32_t main() {
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
dp[0] = 0;
for (int k = 1; k <= n; k++) {
//cout << "K is " << k << "\n";
dp[k] = INF;
vector<int> nv;
vector<int> po(k + 1);
for (int i = 1; i <= n; i++) {
if (v[i] <= k) {
po[v[i]] = nv.size();
nv.push_back(v[i]);
}
}
priority_queue<int> neg;
int pos = 0;
int calc = 0;
int t = 0;
for (int i = k; i >= 1; i--) {
calc = 0;
for (int j = i; j <= k; j++) {
calc += abs((k - j + i - 1) - po[j]);
}
dp[k] = min(dp[k], dp[i - 1] + calc);
//calc -= ((int)neg.size());
//calc += pos;
//calc += abs(po[i] - k + 1);
//dp[k] = min(dp[k], dp[i - 1] + calc);
//while ((!neg.empty()) && (neg.top() == t)) {
// //cout << "removed " << neg.top() << "\n";
// neg.pop();
// pos++;
//}
//if ((po[i] - k + 1) < 0) {
// neg.push(po[i] - k + 1 + t);
// //cout << "added from " << i << " it " << po[i] - k + 1 + t << "\n";
//} else pos++;
//t--;
}
//cout << dp[k] << "\n";
}
cout << dp[n] << "\n";
}
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... |