이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d, t;
cin >> n >> d >> t;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
const long long inf = 2e16;
vector<pair<long long, int>> dp(n + 1, {inf, 0});
auto Check = [&](long long x) {
dp = vector<pair<long long, int>>(n + 1, {inf, 1e9});
dp[n] = {0, 0};
for (int i = n - 1; i >= 0; i--) {
int mn = 1e9;
int delta = 0;
for (int j = i; j < n; j++) {
mn = min(mn, a[j]);
if (mn <= t) {
delta += 1;
}
dp[i] = min(dp[i], {dp[j + 1].first + x + delta, dp[j + 1].second + 1});
}
}
return dp[0].second <= d;
};
long long l = 0, r = inf, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
if (Check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
Check(ans);
cout << dp[0].first - ans * dp[0].second - ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'int main()':
prison.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = l + r >> 1;
| ~~^~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |