제출 #1022924

#제출 시각아이디문제언어결과실행 시간메모리
1022924gygThe short shank; Redemption (BOI21_prison)C++17
0 / 100
4 ms1372 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX_N = 4e3 + 5, MAX_K = 4e3 + 5, INF = 1e9; int n, k, m; array<int, MAX_N> t; int n_keys; array<int, MAX_N> key, aft; void precomp() { for (int i = 1; i <= n; i++) if (t[i] <= m) n_keys++, key[n_keys] = i; key[n_keys + 1] = n + 1; // Speed up for (int i = 1; i <= n_keys; i++) { aft[i] = n_keys + 1; for (int j = i + 1; j <= n_keys; j++) if (t[key[j]] - key[j] < t[key[i]] - key[i]) { aft[i] = j; break; } // cout << i << ": " << aft[i] << endl; } } array<array<int, MAX_K>, MAX_N> dp; void comp() { for (int i = n_keys; i >= 1; i--) { for (int c = 0; c <= k; c++) { int leave = dp[aft[i]][c] + min(m - t[key[i]] + 1, key[aft[i]] - key[i]); int leave2 = dp[i + 1][c] + min(m - t[key[i]] + 1, key[i + 1] - key[i]); int take = (c == 0) ? INF : dp[i + 1][c - 1] + 1; dp[i][c] = min({leave, leave2, take}); // cout << i << " " << c << ": " << dp[i][c] << endl; } } } signed main() { // freopen("prison.in", "r", stdin); cin >> n >> k >> m; for (int i = 1; i <= n; i++) cin >> t[i]; precomp(); comp(); int ans = dp[1][k]; cout << ans << '\n'; }
#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...