Submission #746763

#TimeUsernameProblemLanguageResultExecution timeMemory
746763Abrar_Al_SamitSkyline (IZhO11_skyline)C++17
100 / 100
157 ms56152 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; if(!n1) return ret = solve(i+1, n2, a[i+2]); if(n1) ret = solve(i, n1-1, n2) + 3; if(n1 && n2) ret = solve(i, n1-1, n2-1) + 5; 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...