Submission #1265282

#TimeUsernameProblemLanguageResultExecution timeMemory
1265282kustov_vadim_533Group Photo (JOI21_ho_t3)C++20
44 / 100
5093 ms328 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define len(v) (int)((v).size()) const ll inf = 1e18; inline void solve(){ int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i){ cin >> a[i]; --a[i]; } vector<ll> dp(n + 1, inf); dp[0] = 0; for (int i = 0; i < n; ++i){ vector<int> p; for (int j = 0; j < n; ++j){ if (a[j] >= i){ p.push_back(a[j]); } } vector<int> q(n); for (int j = 0; j < n - i; ++j){ q[p[j]] = j; } for (int j = i; j < n; ++j){ ll res = 0; vector<int> c = q; for (int f = j; f >= i; --f){ res += c[f] - j + f; for (int g = 0; g <= q[f]; ++g) c[p[g]]++; } dp[j + 1] = min(dp[j + 1], dp[i] + res); } } cout << dp[n] << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.precision(60); int t = 1; // cin >> t; while (t--) { solve(); } }
#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...