Submission #982884

#TimeUsernameProblemLanguageResultExecution timeMemory
982884aaaaaarrozGroup Photo (JOI21_ho_t3)C++17
100 / 100
306 ms98548 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int>h(n); for(int i=0;i<n;i++){ cin>>h[i]; h[i]--; } vector<int>pos(n+1); for(int i=0;i<n;i++){ pos[h[i]]=i; } vector<vector<int>>menor(n,vector<int>(n+1,0)); for(int j=n-1;j>0;j--){ for(int i=0;i<=h[j];i++){ menor[j-1][i]=menor[j][i]+1; } for(int i=h[j]+1;i<=n;i++){ menor[j-1][i]=menor[j][i]; } } vector<int>dp(n+1); dp[0]=0; for(int i=1;i<=n;i++){ dp[i]=INT_MAX; int temp=0; for(int j=i-1;j>=0;j--){ temp+=(n-i)+menor[pos[j]][j]-2*menor[pos[j]][i]; if((dp[j]+temp)<dp[i]){ dp[i]=(dp[j]+temp); } } } //XD cout<<dp[n]<<"\n"; return 0; }
#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...