답안 #850965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850965 2023-09-18T03:57:44 Z NamPE Stove (JOI18_stove) C++17
0 / 100
44 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll INF = 1e12;
ll dp[(ll)(5e3 + 1)][(ll)(5e3 + 1)][2];

ll dfs(vector<ll>& a, ll i, ll k, ll state) {
    if(i == a.size()) {
        return (!state ? 0 : INF);
    }

    if(dp[i][k][state] != -1) {
        return dp[i][k][state];
    }

    ll res = INF;

    if(!state && k) {
        res = min(res, dfs(a, i + 1, k - 1, 0) + 1);
        res = min(res, dfs(a, i + 1, k - 1, 1) - a[i]);
    } else if(state) {
        res = min(res, dfs(a, i + 1, k, 1));
        res = min(res, dfs(a, i + 1, k, 0) + a[i] + 1);
    }

    return dp[i][k][state] = res;
}

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

    memset(dp, -1, sizeof dp);

    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);

    for(ll& i : a) {
        cin >> i;
    }

    cout << dfs(a, 0, k, 0);
}

Compilation message

stove.cpp: In function 'll dfs(std::vector<long long int>&, ll, ll, ll)':
stove.cpp:10:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     if(i == a.size()) {
      |        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -