#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
const int INF=2e9;
const int N=300;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
vector<vector<int>> dp(N+1,vector<int>(N+1,INF)),dp1(N+1,vector<int>(N+1,INF));
dp[0][0]=0;
for(int i=0;i<n;i++){
for(int j=0;j<=v[i];j++){
for(int k=j;k<=N;k++){
dp1[k-j][v[i]-j]=min(dp1[k-j][v[i]-j],dp[j][k]+7*j);
}
}
for(int j=N-1;j>=0;j--){
for(int k=N-1;k>=0;k--){
dp1[j][k]=min(dp1[j][k],dp1[j+1][k+1]+5);
}
}
for(int j=N-1;j>=0;j--){
for(int k=N;k>=0;k--){
dp1[j][k]=min(dp1[j][k],dp1[j+1][k]+3);
}
}
dp=dp1;
dp1.assign(N+1,vector<int>(N+1,INF));
}
int ans=INF;
for(int i=0;i<=N;i++){
for(int j=i;j<=N;j++){
ans=min(ans,dp[i][j]+i*2+j*3);
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
2 ms |
980 KB |
Output is correct |
4 |
Correct |
16 ms |
1044 KB |
Output is correct |
5 |
Correct |
3 ms |
960 KB |
Output is correct |
6 |
Correct |
3 ms |
980 KB |
Output is correct |
7 |
Correct |
4 ms |
980 KB |
Output is correct |
8 |
Correct |
4 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
980 KB |
Output is correct |
10 |
Correct |
10 ms |
960 KB |
Output is correct |
11 |
Correct |
39 ms |
1052 KB |
Output is correct |
12 |
Correct |
9 ms |
980 KB |
Output is correct |
13 |
Correct |
46 ms |
980 KB |
Output is correct |
14 |
Correct |
55 ms |
980 KB |
Output is correct |
15 |
Correct |
95 ms |
1032 KB |
Output is correct |
16 |
Correct |
87 ms |
980 KB |
Output is correct |
17 |
Correct |
99 ms |
1032 KB |
Output is correct |
18 |
Correct |
97 ms |
980 KB |
Output is correct |
19 |
Correct |
94 ms |
1036 KB |
Output is correct |
20 |
Correct |
111 ms |
1032 KB |
Output is correct |