Submission #524097

# Submission time Handle Problem Language Result Execution time Memory
524097 2022-02-08T15:47:44 Z inluminas K blocks (IZhO14_blocks) C++17
100 / 100
348 ms 81408 KB
#include"bits/stdc++.h"
using namespace std;
 
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX

const int lmt=1e5+10;
ll dp[lmt][101];

int main(){
  fastio;

  for(int i=0;i<lmt;i++){
    for(int j=2;j<101;j++) dp[i][j]=1e12;
  }

  int n,k;
  cin>>n>>k;
  ll a[n+1];
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }

  for(int i=1;i<=n;i++){
    dp[i][1]=max(dp[i-1][1],a[i]); 
  }

  for(int j=2;j<=k;j++){
    stack<pair<int,ll>>s;
    for(int i=1;i<=n;i++){
      ll mn=1e12;
      while(!s.empty() && a[s.top().first]<=a[i]){
        mn=min(mn,s.top().second);
        s.pop();
      }

      dp[i][j]=min(dp[i][j],mn+a[i]);
      
      if(!s.empty()){
        dp[i][j]=min(dp[i][j],dp[s.top().first][j-1]+a[i]);
        dp[i][j]=min(dp[i][j],dp[s.top().first][j]);
      }

      mn=min(mn,dp[i][j-1]);

      s.push({i,mn});

    }
  }

  cout<<dp[n][k]<<endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 79300 KB Output is correct
2 Correct 38 ms 79332 KB Output is correct
3 Correct 34 ms 79280 KB Output is correct
4 Correct 33 ms 79380 KB Output is correct
5 Correct 47 ms 79364 KB Output is correct
6 Correct 34 ms 79308 KB Output is correct
7 Correct 38 ms 79272 KB Output is correct
8 Correct 36 ms 79264 KB Output is correct
9 Correct 35 ms 79372 KB Output is correct
10 Correct 36 ms 79352 KB Output is correct
11 Correct 36 ms 79308 KB Output is correct
12 Correct 34 ms 79288 KB Output is correct
13 Correct 39 ms 79300 KB Output is correct
14 Correct 40 ms 79336 KB Output is correct
15 Correct 38 ms 79320 KB Output is correct
16 Correct 37 ms 79364 KB Output is correct
17 Correct 35 ms 79360 KB Output is correct
18 Correct 35 ms 79252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 79364 KB Output is correct
2 Correct 39 ms 79252 KB Output is correct
3 Correct 47 ms 79352 KB Output is correct
4 Correct 35 ms 79300 KB Output is correct
5 Correct 35 ms 79320 KB Output is correct
6 Correct 38 ms 79360 KB Output is correct
7 Correct 43 ms 79364 KB Output is correct
8 Correct 38 ms 79320 KB Output is correct
9 Correct 36 ms 79328 KB Output is correct
10 Correct 36 ms 79364 KB Output is correct
11 Correct 36 ms 79364 KB Output is correct
12 Correct 38 ms 79348 KB Output is correct
13 Correct 34 ms 79308 KB Output is correct
14 Correct 39 ms 79332 KB Output is correct
15 Correct 40 ms 79300 KB Output is correct
16 Correct 44 ms 79300 KB Output is correct
17 Correct 37 ms 79364 KB Output is correct
18 Correct 38 ms 79320 KB Output is correct
19 Correct 44 ms 79292 KB Output is correct
20 Correct 36 ms 79308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 79300 KB Output is correct
2 Correct 38 ms 79332 KB Output is correct
3 Correct 34 ms 79280 KB Output is correct
4 Correct 33 ms 79380 KB Output is correct
5 Correct 47 ms 79364 KB Output is correct
6 Correct 34 ms 79308 KB Output is correct
7 Correct 38 ms 79272 KB Output is correct
8 Correct 36 ms 79264 KB Output is correct
9 Correct 35 ms 79372 KB Output is correct
10 Correct 36 ms 79352 KB Output is correct
11 Correct 36 ms 79308 KB Output is correct
12 Correct 34 ms 79288 KB Output is correct
13 Correct 39 ms 79300 KB Output is correct
14 Correct 40 ms 79336 KB Output is correct
15 Correct 38 ms 79320 KB Output is correct
16 Correct 37 ms 79364 KB Output is correct
17 Correct 35 ms 79360 KB Output is correct
18 Correct 35 ms 79252 KB Output is correct
19 Correct 38 ms 79364 KB Output is correct
20 Correct 39 ms 79252 KB Output is correct
21 Correct 47 ms 79352 KB Output is correct
22 Correct 35 ms 79300 KB Output is correct
23 Correct 35 ms 79320 KB Output is correct
24 Correct 38 ms 79360 KB Output is correct
25 Correct 43 ms 79364 KB Output is correct
26 Correct 38 ms 79320 KB Output is correct
27 Correct 36 ms 79328 KB Output is correct
28 Correct 36 ms 79364 KB Output is correct
29 Correct 36 ms 79364 KB Output is correct
30 Correct 38 ms 79348 KB Output is correct
31 Correct 34 ms 79308 KB Output is correct
32 Correct 39 ms 79332 KB Output is correct
33 Correct 40 ms 79300 KB Output is correct
34 Correct 44 ms 79300 KB Output is correct
35 Correct 37 ms 79364 KB Output is correct
36 Correct 38 ms 79320 KB Output is correct
37 Correct 44 ms 79292 KB Output is correct
38 Correct 36 ms 79308 KB Output is correct
39 Correct 37 ms 79344 KB Output is correct
40 Correct 42 ms 79256 KB Output is correct
41 Correct 37 ms 79308 KB Output is correct
42 Correct 46 ms 79308 KB Output is correct
43 Correct 37 ms 79336 KB Output is correct
44 Correct 48 ms 79284 KB Output is correct
45 Correct 35 ms 79300 KB Output is correct
46 Correct 39 ms 79300 KB Output is correct
47 Correct 36 ms 79300 KB Output is correct
48 Correct 37 ms 79324 KB Output is correct
49 Correct 35 ms 79304 KB Output is correct
50 Correct 36 ms 79308 KB Output is correct
51 Correct 42 ms 79360 KB Output is correct
52 Correct 35 ms 79308 KB Output is correct
53 Correct 36 ms 79332 KB Output is correct
54 Correct 37 ms 79308 KB Output is correct
55 Correct 39 ms 79300 KB Output is correct
56 Correct 36 ms 79332 KB Output is correct
57 Correct 49 ms 79300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 79300 KB Output is correct
2 Correct 38 ms 79332 KB Output is correct
3 Correct 34 ms 79280 KB Output is correct
4 Correct 33 ms 79380 KB Output is correct
5 Correct 47 ms 79364 KB Output is correct
6 Correct 34 ms 79308 KB Output is correct
7 Correct 38 ms 79272 KB Output is correct
8 Correct 36 ms 79264 KB Output is correct
9 Correct 35 ms 79372 KB Output is correct
10 Correct 36 ms 79352 KB Output is correct
11 Correct 36 ms 79308 KB Output is correct
12 Correct 34 ms 79288 KB Output is correct
13 Correct 39 ms 79300 KB Output is correct
14 Correct 40 ms 79336 KB Output is correct
15 Correct 38 ms 79320 KB Output is correct
16 Correct 37 ms 79364 KB Output is correct
17 Correct 35 ms 79360 KB Output is correct
18 Correct 35 ms 79252 KB Output is correct
19 Correct 38 ms 79364 KB Output is correct
20 Correct 39 ms 79252 KB Output is correct
21 Correct 47 ms 79352 KB Output is correct
22 Correct 35 ms 79300 KB Output is correct
23 Correct 35 ms 79320 KB Output is correct
24 Correct 38 ms 79360 KB Output is correct
25 Correct 43 ms 79364 KB Output is correct
26 Correct 38 ms 79320 KB Output is correct
27 Correct 36 ms 79328 KB Output is correct
28 Correct 36 ms 79364 KB Output is correct
29 Correct 36 ms 79364 KB Output is correct
30 Correct 38 ms 79348 KB Output is correct
31 Correct 34 ms 79308 KB Output is correct
32 Correct 39 ms 79332 KB Output is correct
33 Correct 40 ms 79300 KB Output is correct
34 Correct 44 ms 79300 KB Output is correct
35 Correct 37 ms 79364 KB Output is correct
36 Correct 38 ms 79320 KB Output is correct
37 Correct 44 ms 79292 KB Output is correct
38 Correct 36 ms 79308 KB Output is correct
39 Correct 37 ms 79344 KB Output is correct
40 Correct 42 ms 79256 KB Output is correct
41 Correct 37 ms 79308 KB Output is correct
42 Correct 46 ms 79308 KB Output is correct
43 Correct 37 ms 79336 KB Output is correct
44 Correct 48 ms 79284 KB Output is correct
45 Correct 35 ms 79300 KB Output is correct
46 Correct 39 ms 79300 KB Output is correct
47 Correct 36 ms 79300 KB Output is correct
48 Correct 37 ms 79324 KB Output is correct
49 Correct 35 ms 79304 KB Output is correct
50 Correct 36 ms 79308 KB Output is correct
51 Correct 42 ms 79360 KB Output is correct
52 Correct 35 ms 79308 KB Output is correct
53 Correct 36 ms 79332 KB Output is correct
54 Correct 37 ms 79308 KB Output is correct
55 Correct 39 ms 79300 KB Output is correct
56 Correct 36 ms 79332 KB Output is correct
57 Correct 49 ms 79300 KB Output is correct
58 Correct 41 ms 79464 KB Output is correct
59 Correct 42 ms 79900 KB Output is correct
60 Correct 47 ms 79928 KB Output is correct
61 Correct 104 ms 79956 KB Output is correct
62 Correct 312 ms 80828 KB Output is correct
63 Correct 63 ms 80816 KB Output is correct
64 Correct 156 ms 80788 KB Output is correct
65 Correct 36 ms 79260 KB Output is correct
66 Correct 40 ms 79364 KB Output is correct
67 Correct 37 ms 79372 KB Output is correct
68 Correct 48 ms 79360 KB Output is correct
69 Correct 40 ms 79328 KB Output is correct
70 Correct 38 ms 79364 KB Output is correct
71 Correct 55 ms 79504 KB Output is correct
72 Correct 37 ms 79400 KB Output is correct
73 Correct 42 ms 79428 KB Output is correct
74 Correct 41 ms 79952 KB Output is correct
75 Correct 49 ms 79968 KB Output is correct
76 Correct 102 ms 80004 KB Output is correct
77 Correct 348 ms 80820 KB Output is correct
78 Correct 53 ms 80712 KB Output is correct
79 Correct 200 ms 80772 KB Output is correct
80 Correct 45 ms 80836 KB Output is correct
81 Correct 67 ms 80708 KB Output is correct
82 Correct 308 ms 80836 KB Output is correct
83 Correct 38 ms 79364 KB Output is correct
84 Correct 41 ms 79384 KB Output is correct
85 Correct 54 ms 79572 KB Output is correct
86 Correct 52 ms 79524 KB Output is correct
87 Correct 43 ms 79496 KB Output is correct
88 Correct 41 ms 79948 KB Output is correct
89 Correct 52 ms 80268 KB Output is correct
90 Correct 126 ms 80300 KB Output is correct
91 Correct 341 ms 81408 KB Output is correct
92 Correct 58 ms 81404 KB Output is correct
93 Correct 173 ms 81408 KB Output is correct
94 Correct 52 ms 79392 KB Output is correct
95 Correct 59 ms 79556 KB Output is correct
96 Correct 40 ms 79348 KB Output is correct
97 Correct 38 ms 79292 KB Output is correct
98 Correct 58 ms 79300 KB Output is correct
99 Correct 36 ms 79324 KB Output is correct