Submission #1016397

#TimeUsernameProblemLanguageResultExecution timeMemory
1016397HanksburgerGroup Photo (JOI21_ho_t3)C++17
100 / 100
137 ms98640 KiB
#include <bits/stdc++.h> using namespace std; int x[5005][5005], a[5005], b[5005], dp[5005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i=1; i<=n; i++) { cin >> a[i]; b[a[i]]=i; } for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) x[i][j]=x[i-1][j]+(j>=b[i]); for (int i=1; i<=n; i++) { dp[i]=1e9; int s=0; for (int j=i; j; j--) { s+=x[i][n]-x[i][b[j]]-x[j][n]+x[j][b[j]]+x[n][b[j]]-x[i][b[j]]; dp[i]=min(dp[i], dp[j-1]+s); } } cout << dp[n]; }
#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...