Submission #668974

#TimeUsernameProblemLanguageResultExecution timeMemory
668974mychecksedadThe short shank; Redemption (BOI21_prison)C++17
10 / 100
64 ms12492 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 = 5100, MOD = 1e9+7; int n, d, a[N], T, dp[M][M][2], pref[N][2], suf[N], ans; void solve(){ cin >> n >> d >> T; for(int i = 1; i <= n; ++i) cin >> a[i]; pref[0][0] = 0, pref[0][1] = MOD, suf[n + 1] = 0; int cur = MOD; for(int i = 1; i <= n; ++i){ pref[i][0] = pref[i - 1][0]; if(min(a[i], cur) <= T) pref[i][0]++; cur = min(a[i] + 1, cur + 1); pref[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][0] + suf[i + 1]); } }else{ for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j){ if(j == 0 || i == 0){ dp[i][j][0] = pref[i][0]; dp[i][j][1] = pref[i][1]; }else{ dp[i][j][0] = n; dp[i][j][1] = MOD; } } for(int i = 1; i <= n; ++i){ bool is = a[i] <= T; for(int j = 1; j <= d; ++j){ bool added = min(a[i], dp[i - 1][j][1] + 1) <= T; if(dp[i - 1][j - 1][0] + is > dp[i - 1][j][0] + added){ dp[i][j][0] = dp[i - 1][j][0] + added; dp[i][j][1] = min(a[i], dp[i - 1][j][1] + 1); }else{ dp[i][j][0] = dp[i - 1][j - 1][0] + is; dp[i][j][1] = a[i]; } } } ans = dp[n][d][0]; } 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...