#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long int
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
int nxt(){ int x;cin>>x; return x; }
const int mod = 1e9 +7, sze = 3e2 +23, inf = LLONG_MAX, LG = 20;
// mt19937 rng(time(0));
int dp[sze][sze][sze];
//saksuk, I checked someone's code
void fast(){
int n;
cin>>n;
vector<int> arr(n+1,0);
for(int i=0;i<n;i++){
cin>>arr[i+1];
}
for(int i=0;i<sze;i++){
for(int j=0;j<sze;j++){
for(int k =0; k<sze;k++){
dp[i][j][k]=inf;
}
}
}
for(int i =0;i<=arr[1];i++){
dp[1][0][i]=3*i;
}
for(int i =2;i<=n;i++){
for(int j=0;j<=arr[i-1];j++){
for(int k =0;k<=arr[i];k++){
if(k>0){
dp[i][j][k]=dp[i][j][k-1]+3;
}
if(k>0 && j>0){
dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k-1] + 5);
}
int sil = min(j,k);
if(sil<=arr[i-2]){
dp[i][j][k]=min(dp[i][j][k],dp[i-1][ arr[i-2] -sil][ j - sil] + sil*7 + 3*(k-sil));
}
}
}
}
putr(dp[ n][arr[n-1] ][arr[n]]);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
160 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |