답안 #850977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850977 2023-09-18T04:26:31 Z NamPE Stove (JOI18_stove) C++17
20 / 100
1000 ms 168016 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

map<tuple<ll, ll, ll>, ll> dp;

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

    if (dp.count({i, k, state})) {
        return dp[{i, k, state}];
    }

    ll res = INT_MAX;

    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);

    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:9:11: 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]
    9 |     if (i == a.size()) {
      |         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 800 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 800 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 20 ms 5464 KB Output is correct
11 Correct 278 ms 46928 KB Output is correct
12 Execution timed out 1053 ms 168016 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 800 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 20 ms 5464 KB Output is correct
11 Correct 278 ms 46928 KB Output is correct
12 Execution timed out 1053 ms 168016 KB Time limit exceeded
13 Halted 0 ms 0 KB -