이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = INT_MAX;
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 : INT_MAX);
}
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 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);
}
컴파일 시 표준 에러 (stderr) 메시지
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()) {
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |