답안 #549971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549971 2022-04-17T02:11:09 Z colossal_pepe 스카이라인 (IZhO11_skyline) C++17
0 / 100
2000 ms 47964 KB
#include <iostream>
#include <cstring>
using namespace std;

/*
dp[i][carry][carry, pass forward] = min cost for range [i...n]
*/

const int INF = 1e9;

int n, h[301], dp[301][201][201];

int brutus(int i, int c1, int c2) {
    if (i >= n) return 0;
    if (dp[i][c1][c2] != -1) return dp[i][c1][c2];
    int h_cur = h[i] - c1 - c2;
    dp[i][c1][c2] = INF;
    for (int cnt3 = 0; cnt3 <= h_cur; cnt3++) {
        for (int cnt2 = 0; cnt2 <= h_cur - cnt3; cnt2++) {
            dp[i][c1][c2] = min(dp[i][c1][c2], brutus(i + 1, c2 + cnt2, cnt3) + 7 * cnt3 + 5 * cnt2 + 3 * (h_cur - cnt3 - cnt2));
        }
    }
    return dp[i][c1][c2];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    cout << brutus(0, 0, 0) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 47828 KB Output is correct
2 Correct 18 ms 47828 KB Output is correct
3 Correct 19 ms 47964 KB Output is correct
4 Correct 19 ms 47828 KB Output is correct
5 Correct 20 ms 47852 KB Output is correct
6 Correct 20 ms 47916 KB Output is correct
7 Correct 23 ms 47920 KB Output is correct
8 Correct 71 ms 47828 KB Output is correct
9 Correct 223 ms 47908 KB Output is correct
10 Correct 1078 ms 47900 KB Output is correct
11 Execution timed out 2096 ms 47828 KB Time limit exceeded
12 Halted 0 ms 0 KB -