Submission #409891

#TimeUsernameProblemLanguageResultExecution timeMemory
409891CaroLindaThe short shank; Redemption (BOI21_prison)C++14
35 / 100
119 ms45744 KiB
#include <bits/stdc++.h> const int MAXN = 4010 ; using namespace std ; int N , D , T , toGet, toFill = 1 ; int t[MAXN] ; int dp[2][MAXN]; int cost[MAXN][MAXN] ; void solve(int l, int r, int optmin , int optmax ) { if(l > r) return ; int mid = (l+r)>>1 ; int opt = optmin ; dp[toFill][mid] = cost[opt][mid]+dp[toGet][opt-1] ; for(int i = optmin+1 ; i <= min(mid,optmax) ; i++ ) { int newCost = cost[i][mid] + dp[toGet][i-1] ; if(newCost >= dp[toFill][mid]) continue ; opt = i ; dp[toFill][mid] = newCost ; } solve(l, mid-1, optmin, opt ) ; solve(mid+1, r, opt, optmax ); } int main() { scanf("%d %d %d", &N, &D, &T ) ; for(int i = 1 ; i <= N ; i++ ) scanf("%d", &t[i] ) ; for(int i = 1 ; i <= N ; i++ ) { int s = t[i]+1 ; cost[i][i] = t[i] <= T ; for(int j = i+1 ; j <= N ; j++ , s++ ) { s = min(s, t[j] ) ; cost[i][j] = cost[i][j-1]+(s <= T ) ; } } for(int i = 1 ; i <= N ; i++ ) dp[0][i] = cost[1][i] ; for(int i = 1 ; i <= D ; i++ , swap(toGet, toFill) ) { for(int j = 1 ; j <= i ; j++ ) dp[toFill][j] = dp[toGet][j] ; solve(i+1, N, i+1, N ) ; } printf("%d\n", dp[toGet][N] ) ; }

Compilation message (stderr)

prison.cpp: In function 'int main()':
prison.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d %d %d", &N, &D, &T  ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
prison.cpp:35:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  for(int i = 1 ; i <= N ; i++ ) scanf("%d", &t[i] ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~
#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...