Submission #593136

#TimeUsernameProblemLanguageResultExecution timeMemory
593136piOOEGroup Photo (JOI21_ho_t3)C++17
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), pl(n); for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } for (int i = 0; i < n; ++i) { int cnt = 0; for (int j = 0; j < n; ++j) { if (a[j] >= i) { ++cnt; } if (a[j] == i) { pl[i] = cnt; break; } } } vector<vector<int>> dp(n, vector<int>(n + 1)); dp[n - 1][1] = 0; for (int x = n - 2; x >= 0; --x) { dp[x][1] = n * n; for (int cnt = 1; cnt + 1 + x <= n; ++cnt) { dp[x][1] = min(dp[x][1], dp[x + 1][cnt] + abs(pl[x] - 1)); } for (int cnt = 2; x + cnt <= n; ++cnt) { dp[x][cnt] = dp[x + 1][cnt - 1] + abs(pl[x] - cnt); } } int ans = n * n; for (int i = 1; i <= n; ++i) { ans = min(ans, dp[0][i]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...