Submission #668863

#TimeUsernameProblemLanguageResultExecution timeMemory
668863mychecksedadThe short shank; Redemption (BOI21_prison)C++17
15 / 100
57 ms6356 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 = n, 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); } if(n > 500){ 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 i = 1; i <= n; ++i){ for(int j = 1; j <= d; ++j){ for(int k = 0; k <= i; ++k){ dp[i][j] = min(dp[i][j], dp[k][j - 1] + pre[k + 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...