# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
658046 | kusssso | Stove (JOI18_stove) | C++17 | 115 ms | 82932 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll inf = 1e18;
int n, k;
ll t[N];
namespace sub2 {
ll dp[5005][5005];
void solve() {
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf;
dp[0][0] = 0;
for (int z = 1; z <= k; z++) {
ll min_dp = inf;
for (int i = 1; i <= n; i++) {
min_dp = min(min_dp, dp[i - 1][z - 1] - t[i]);
dp[i][z] = min(dp[i][z], min_dp + t[i] + 1);
}
}
cout << dp[n][k];
}
};
namespace full {
void solve() {
multiset<ll> s;
for (int i = 2; i <= n; i++) {
s.insert(t[i] - t[i - 1] - 1);
if (s.size() > k - 1) {
s.erase(s.begin());
}
}
ll ans = t[n] - t[1] + 1;
for (auto &x : s) {
ans -= x;
}
cout << ans;
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> t[i];
if (n <= 5000) sub2::solve();
else full::solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |