Submission #746742

#TimeUsernameProblemLanguageResultExecution timeMemory
746742Abrar_Al_SamitSkyline (IZhO11_skyline)C++17
0 / 100
23 ms50468 KiB
#include<bits/stdc++.h> using namespace std; int dp[305][205][205]; int n; int a[305]; int op3(int i, int &n1, int &n2) { int x = n1, y = n2, z = a[i+2]; int ret = 0; int take = min({x, y, z}); ret = take * 7; x -= take; y -= take; z -= take; if(x) { if(y) { take = min(x, y); ret += take * 5; x -= take; y -= take; if(x) { ret += x * 3; } } else { ret += x * 3; } } n1 = y, n2 = z; return ret; } int solve(int i, int n1, int n2) { if(i>n) return 0; int &ret = dp[i][n1][n2]; if(ret!=-1) return ret; ret = solve(i+1, n2, a[i+2]) + n1 * 3; ret = solve(i+1, max(0, n2-n1), a[i+2]) + min(n1, n2) * 5 + max(n1-n2, 0) * 3; int c = op3(i, n1, n2); ret = min(ret, c+solve(i+1, n1, n2)); return ret; } void PlayGround() { cin>>n; for(int i=1; i<=n; ++i) { cin>>a[i]; } memset(dp, -1, sizeof dp); cout<<solve(1, a[1], a[2])<<'\n'; // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...