Submission #333808

# Submission time Handle Problem Language Result Execution time Memory
333808 2020-12-07T20:06:06 Z limabeans Skyline (IZhO11_skyline) C++17
100 / 100
358 ms 232684 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll inf = 1e18;

const int maxn = 314;



int n;
int a[maxn];
ll dp[maxn][maxn][maxn];


void setmin(ll &x, ll y) {
    x = min(x, y);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    for (int i=1; i<=n; i++) {
	cin>>a[i];
    }


    for (int i=0; i<=n; i++) {
	for (int j=0; j<maxn; j++) {
	    for (int k=0; k<maxn; k++) {
		dp[i][j][k] = inf;
	    }
	}
    }


    dp[1][0][a[1]] = 0;

    for (int i=1; i<=n; i++) {
	for (int j=maxn-1; j>=0; j--) {
	    for (int k=maxn-1; k>=0; k--) {
		if (k>0) {
		    setmin(dp[i][j][k-1], dp[i][j][k]+3);
		}
		if (j>0 && k>0) {
		    setmin(dp[i][j-1][k-1], dp[i][j][k]+5);
		}
	    }
	}

	if (i==n) {
	    break;
	}



	// j....k.....a[i+1]
	for (int j=0; j<maxn; j++) {
	    for (int k=0; k<maxn; k++) {
		if (a[i+1] >= j && k >= j) {
		    setmin(dp[i+1][k-j][a[i+1]-j], dp[i][j][k] + 7*j);
		}
	    }
	}
    }

    cout<<dp[n][0][0]<<endl;
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 6 ms 4972 KB Output is correct
4 Correct 70 ms 55148 KB Output is correct
5 Correct 7 ms 5740 KB Output is correct
6 Correct 11 ms 8812 KB Output is correct
7 Correct 10 ms 8044 KB Output is correct
8 Correct 8 ms 6508 KB Output is correct
9 Correct 15 ms 11116 KB Output is correct
10 Correct 27 ms 19692 KB Output is correct
11 Correct 158 ms 109932 KB Output is correct
12 Correct 34 ms 24300 KB Output is correct
13 Correct 181 ms 129388 KB Output is correct
14 Correct 222 ms 154860 KB Output is correct
15 Correct 319 ms 212588 KB Output is correct
16 Correct 292 ms 190956 KB Output is correct
17 Correct 358 ms 232684 KB Output is correct
18 Correct 354 ms 231148 KB Output is correct
19 Correct 339 ms 222572 KB Output is correct
20 Correct 357 ms 232684 KB Output is correct