Submission #993706

#TimeUsernameProblemLanguageResultExecution timeMemory
993706simona1230Tortoise (CEOI21_tortoise)C++17
0 / 100
1 ms2392 KiB
#include <bits/stdc++.h> using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n,a[1001]; void read() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; } int dp[1001][3001]; void solve() { for(int i=0;i<=n;i++) { for(int j=0;j<=2*n;j++) { dp[i][j]=-1e9; } } int sum=0; for(int i=1;i<=n;i++) { if(a[i]==1)dp[i][i]=1,sum++; } int ans=0; dp[0][0]=0; for(int i=1;i<=n;i++) { for(int j=i;j<=2*i;j++) { for(int pr=1;pr<i;pr++) { if(a[pr]!=1)continue; for(int d=1;d<=n;d++) { if(a[d]!=-1)continue; int f=j-(abs(d-i)+abs(d-pr)); if(f>=0)dp[i][j]=max(dp[i][j],dp[pr][f]+1); } } //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; ans=max(ans,dp[i][j]); } } cout<<sum-ans<<endl; } int main() { speed(); read(); solve(); 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...