Submission #1038888

#TimeUsernameProblemLanguageResultExecution timeMemory
1038888OtalpGroup Photo (JOI21_ho_t3)C++14
100 / 100
250 ms98344 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pb push_back #define ff first #define ss second int a[5001]; int cnt[5001][5001]; int dp[5001]; int ddp[5001]; int pos[200100]; void solve(){ int n; cin>>n; for(int i=1; i<=n; i++){ cin>>a[i]; pos[a[i]] = i; } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ cnt[i][j] = cnt[i-1][j] + (a[i] >= j ?1 :0); } } for(int i=1; i<=n; i++){ int sum = 0; dp[i] = 1e9; for(int j=i; j>=1; j--){ sum += cnt[pos[j]-1][i+1]; sum += (cnt[n][j] - cnt[n][i+1]) - (cnt[pos[j]][j] - cnt[pos[j]][i+1]); dp[i] = min(dp[i], sum + dp[j-1]); } //cout<<dp[i]<<' '; } cout<<dp[n]; } signed main(){ 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...