# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
683955 | KiriLL1ca | 스카이라인 (IZhO11_skyline) | C++17 | 179 ms | 222460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pw(x) (1ll << x)
#define vec vector
#define sz(x) (int)((x).size())
#define forn(i, s, f) for (int i = s; i <= f; ++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
#define int long long
const int N = 305;
const int inf = 1e18 + 7;
int dp[N][N][N], a[N];
inline void solve () {
int n; cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n == 1) { cout << a[1] * 3; return; }
forn (i, 0, N-1) forn (f, 0, N-1) forn (s, 0, N-1) dp[i][f][s] = inf;
dp[0][0][0] = 0;
for (int i = 0; i <= n; ++i) {
int q = a[i + 1], w = a[i + 2];
for (int f = 0; f <= q; ++f) {
for (int s = 0; s <= w; ++s) {
if (f == q) umin(dp[i + 1][s][0], dp[i][f][s]);
if (f + 1 <= q) umin(dp[i][f + 1][s], dp[i][f][s] + 3);
if (s + 1 <= w) umin(dp[i][f][s + 1], dp[i][f][s] + 3);
if (f + 1 <= q && s + 1 <= w) umin(dp[i][f + 1][s + 1], dp[i][f][s] + 5);
if (s + q - f <= w) umin(dp[i + 1][s + q - f][q - f], dp[i][f][s] + 7 * (q - f));
}
}
}
cout << dp[n + 1][0][0] << endl;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |