# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333808 | limabeans | Skyline (IZhO11_skyline) | C++17 | 358 ms | 232684 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |