제출 #1206591

#제출 시각아이디문제언어결과실행 시간메모리
1206591lopkusThe short shank; Redemption (BOI21_prison)C++17
15 / 100
2098 ms589824 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n, d, t; std::cin >> n >> d >> t; std::vector<int> a(n + 1); for(int i = 1; i <= n; i++) { std::cin >> a[i]; } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(d + 1, n + 1)); dp[0][0] = 0; std::vector<int> c = a; for(int i = 1; i <= n; i++) { if(i > 1) c[i] = std::min(c[i], c[i - 1] + 1); dp[i][0] = dp[i - 1][0]; if(c[i] <= t) { dp[i][0] += 1; } } std::vector<std::vector<int>> cost(n + 1, std::vector<int>(n + 1)); for(int i = 1; i <= n; i++) { std::vector<int> c = a; cost[i][i] = (c[i] <= t); for(int j = i + 1; j <= n; j++) { c[j] = std::min(c[j], c[j - 1] + 1); cost[i][j] = cost[i][j - 1]; if(c[j] <= t) { cost[i][j] += 1; } } } for(int i = 1; i <= n; i++) { for(int c = 1; c <= d; c++) { for(int j = i; j >= 1; j--) { dp[i][c] = std::min(dp[i][c], dp[j - 1][c - 1] + cost[j][i]); } } } int ans = n + 1; for(int c = 1; c <= d; c++) { ans = std::min(ans, dp[n][c]); } std::cout << ans; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; //std::cin >> t; while (t--) { solve(); } return 0; }
#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...