Submission #1016399

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