제출 #666354

#제출 시각아이디문제언어결과실행 시간메모리
666354MilosMilutinovicThe short shank; Redemption (BOI21_prison)C++14
0 / 100
2065 ms22772 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...