Submission #338194

# Submission time Handle Problem Language Result Execution time Memory
338194 2020-12-22T16:36:55 Z amunduzbaev Skyline (IZhO11_skyline) C++14
100 / 100
239 ms 101228 KB
/** 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 time Memory Grader output
1 Correct 55 ms 100716 KB Output is correct
2 Correct 61 ms 100784 KB Output is correct
3 Correct 55 ms 100716 KB Output is correct
4 Correct 55 ms 100672 KB Output is correct
5 Correct 56 ms 100736 KB Output is correct
6 Correct 70 ms 100716 KB Output is correct
7 Correct 57 ms 100764 KB Output is correct
8 Correct 55 ms 100724 KB Output is correct
9 Correct 56 ms 100716 KB Output is correct
10 Correct 59 ms 100736 KB Output is correct
11 Correct 80 ms 101100 KB Output is correct
12 Correct 61 ms 100716 KB Output is correct
13 Correct 74 ms 100972 KB Output is correct
14 Correct 89 ms 101120 KB Output is correct
15 Correct 174 ms 101100 KB Output is correct
16 Correct 174 ms 101100 KB Output is correct
17 Correct 239 ms 100756 KB Output is correct
18 Correct 229 ms 101032 KB Output is correct
19 Correct 229 ms 101228 KB Output is correct
20 Correct 237 ms 101100 KB Output is correct