# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338171 | juggernaut | Skyline (IZhO11_skyline) | C++14 | 194 ms | 49604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;
const int N=303;
const int M=202;
int dp[N][M][M],arr[N],n;
int rec(int pos,int a1,int a2){
if(pos>=n)
return min(a1,a2)*5+(max(a1,a2)-min(a1,a2))*3;
int &ret=dp[pos][a1][a2];
if(~ret)
return ret;
ret=INF;
int val=min(arr[pos],min(a1,a2));
if(val==a2)
ret=min(ret,rec(pos+1,arr[pos]-val,a1-val)+val*7);
if(a1 and a2)
ret=min(ret,rec(pos,a1-1,a2-1)+5);
if(a2)
ret=min(ret,rec(pos,a1,a2-1)+3);
return ret;
//a2 a1 a[pos]
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",arr+i);
memset(dp,-1,sizeof dp);
printf("%d\n",rec(2,arr[1],arr[0]));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |