Submission #961105

#TimeUsernameProblemLanguageResultExecution timeMemory
961105happy_nodeGroup Photo (JOI21_ho_t3)C++17
44 / 100
5015 ms468 KiB
#include <bits/stdc++.h> using namespace std; const int MX=5005; int N; int H[MX], dp[MX]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N; for(int i=1;i<=N;i++) cin>>H[i]; for(int i=1;i<=N;i++) dp[i]=1e9; for(int i=0;i<=N;i++) { for(int k=i+1;k<=N;k++) { int cost=0; for(int j=k;j>i;j--) { for(int x=1;x<=N;x++) { if(H[x]==j) break; cost+=(i<H[x]&&H[x]<j)||k<H[x]; } } dp[k]=min(dp[k],dp[i]+cost); } } cout<<dp[N]<<'\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...