Submission #338194

#TimeUsernameProblemLanguageResultExecution timeMemory
338194amunduzbaevSkyline (IZhO11_skyline)C++14
100 / 100
239 ms101228 KiB
/** made by amunduzbaev **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vll vector<ll> #define vii vector<int> #define vpii vector<pii> #define vpll vector<pll> const int N = 305, M = 205; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); ll n, m, k, ans; ll dp[N][M][M], a[N]; int rec(ll pos, ll a1, ll a2){ if(pos >= n) return min(a1, a2) * 5 + (max(a1, a2) - min(a1, a2))*3; ll &res = dp[pos][a1][a2]; if(res != -1)return res; res = inf; ll mn = min(a1, min(a2, a[pos])); if(mn == a1) res = min(res, rec(pos+1, a2-a1, a[pos]-a1) + mn*7ll); if(a1 && a2) res = min(res, rec(pos, a1-1, a2-1)+5ll); if(a1) res = min(res, rec(pos, a1-1, a2)+3ll); return res; } void solve(){ fastios cin>>n; for(int i=0;i<n;i++) cin>>a[i]; memset(dp, -1, sizeof(dp)); ans = rec(2ll, a[0], a[1]); cout<<ans<<"\n"; return; } int main(){ fastios int t = 1; if(t) solve(); else { cin>>t; while (t--) solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...