제출 #668868

#제출 시각아이디문제언어결과실행 시간메모리
668868mychecksedadThe short shank; Redemption (BOI21_prison)C++17
10 / 100
60 ms10252 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pb push_back #define all(x) x.begin(), x.end() const int N = 2e6+10, M = 5e3, MOD = 1e9+7; int n, d, a[N], T, dp[M][M], pref[N], suf[N], ans, pre[M][M]; void solve(){ cin >> n >> d >> T; for(int i = 1; i <= n; ++i) cin >> a[i]; pref[0] = 0, suf[n + 1] = 0; int cur = MOD; for(int i = 1; i <= n; ++i){ pref[i] = pref[i - 1]; if(min(a[i], cur) <= T) pref[i]++; cur = min(a[i] + 1, cur + 1); } ans = n; if(n > 5000){ deque<pair<int, int>> q; for(int i = n; i >= 1; --i){ suf[i] = suf[i + 1]; q.push_front({a[i], i}); while(!q.empty()){ if(min(q.front().first, a[i] + q.front().second - i) <= T){ suf[i]++; q.pop_front(); }else{ break; } } } for(int i = 0; i <= n; ++i){ ans = min(ans, pref[i] + suf[i + 1]); } }else{ for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) pre[i][j] = 0; for(int i = 1; i <= n; ++i){ pre[i][i] = a[i] <= T; int cur = a[i] + 1; for(int j = i + 1; j <= n; ++j){ pre[i][j] = pre[i][j - 1]; if(min(a[j], cur) <= T) pre[i][j]++; cur = min(a[j] + 1, cur + 1); } } for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) dp[i][j] = (j == 0 ? pref[i] : n); dp[0][0] = 0; for(int j = 1; j <= d; ++j){ int m = 1; for(int i = 1; i <= n; ++i){ while(m < i && dp[m][j - 1] + pre[m + 1][i] >= dp[m + 1][j - 1] + pre[m + 2][i]){ m++; } dp[i][j] = min(dp[i][j], dp[m][j - 1] + pre[m + 1][i]); } } ans = dp[n][d]; } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); 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...