Submission #850977

#TimeUsernameProblemLanguageResultExecution timeMemory
850977NamPEStove (JOI18_stove)C++17
20 / 100
1053 ms168016 KiB
#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 (stderr)

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()) {
      |         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...