Submission #1273556

#TimeUsernameProblemLanguageResultExecution timeMemory
1273556KindaGoodGamesThe short shank; Redemption (BOI21_prison)C++20
0 / 100
35 ms2680 KiB
// #pragma GCC optimize("O3, unroll-loops, Ofast") #include<bits/stdc++.h> using namespace std; vector<int> arr; const int MAXN = 4000; const int MAXD = 2; int C[1][MAXN]; int dp[MAXD][MAXN]; int n,d,t; int INF = numeric_limits<int>::max()/2; int cost(int l, int r){ int time = INF; int cnt = 0; for(int i = l; i <= r; i++){ time = min(time+1, arr[i]); if(time <= t){ cnt++; } } return cnt; } void calc(int k, int l, int r, int optl, int optr){ if(l >= r) return; int mid = (l+r)/2; int opt = -1; for(int j = optl; j <= min(optr,mid); j++){ int c = cost(j,mid); // int c = C[j][mid]; if(dp[k][mid] > dp[k-1][j-1] + c){ opt = j; dp[k][mid] = dp[k-1][j-1] + c; } } calc(k,l,mid,optl,opt); calc(k,mid+1,r,opt,optr); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> d >> t; arr.resize(n); for(int i = 0; i < n; i++){ cin >> arr[i]; } // C.resize(n, vector<int>(n)); for(int i = 0; i < 1; i++){ int time = INF; int cnt = 0; for(int j = i; j < n; j++){ time = min(time+1, arr[j]); if(time <= t){ cnt++; } C[i][j] = cnt; } } // d pillows, [0;i] // dp.resize(d+1, vector<int>(n, INF)); for(int i = 0; i < MAXD; i++){ for(int j = 0; j < MAXN; j++){ dp[i][j] = INF; } } for(int i = 0; i < n; i++){ dp[0][i] = C[0][i]; } for(int i = 1; i <= d; i++){ calc(i,0,n,0,n); } cout << dp[d][n-1] << endl; }
#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...