Submission #491085

# Submission time Handle Problem Language Result Execution time Memory
491085 2021-11-30T13:24:47 Z tar_palantir K blocks (IZhO14_blocks) C++17
100 / 100
226 ms 88528 KB
#include<bits/stdc++.h>
#define int     long long
#define task    "block"
using namespace std;
using ii=pair<int,int>;

const int mn=1e5+11;
const int mk=111;

int n,k;
int a[mn];
int dp[mn][mk];

ii st[mn];
int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>k;
    
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    
    for(int j=1;j<=k;j++){
    	int cnt=0;
    	for(int i=j;i<=n;i++){
    		int mval=dp[i-1][j-1];
    		
    		while(cnt && a[st[cnt].first]<=a[i]){
    			mval=min(mval,st[cnt].second);
    			cnt--;
    		}
    		
    		dp[i][j]=min(dp[st[cnt].first][j],mval+a[i]);
    		st[++cnt]=ii(i,mval);
    	}	
    }
    
    cout<<dp[n][k];
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 87188 KB Output is correct
2 Correct 33 ms 87104 KB Output is correct
3 Correct 33 ms 87108 KB Output is correct
4 Correct 34 ms 87216 KB Output is correct
5 Correct 37 ms 87108 KB Output is correct
6 Correct 31 ms 87136 KB Output is correct
7 Correct 36 ms 87120 KB Output is correct
8 Correct 32 ms 87156 KB Output is correct
9 Correct 32 ms 87140 KB Output is correct
10 Correct 33 ms 87092 KB Output is correct
11 Correct 31 ms 87132 KB Output is correct
12 Correct 32 ms 87108 KB Output is correct
13 Correct 35 ms 87144 KB Output is correct
14 Correct 32 ms 87188 KB Output is correct
15 Correct 32 ms 87108 KB Output is correct
16 Correct 32 ms 87180 KB Output is correct
17 Correct 32 ms 87144 KB Output is correct
18 Correct 34 ms 87176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 87168 KB Output is correct
2 Correct 33 ms 87180 KB Output is correct
3 Correct 34 ms 87200 KB Output is correct
4 Correct 33 ms 87096 KB Output is correct
5 Correct 32 ms 87084 KB Output is correct
6 Correct 33 ms 87108 KB Output is correct
7 Correct 31 ms 87108 KB Output is correct
8 Correct 32 ms 87108 KB Output is correct
9 Correct 32 ms 87200 KB Output is correct
10 Correct 32 ms 87156 KB Output is correct
11 Correct 33 ms 87188 KB Output is correct
12 Correct 34 ms 87180 KB Output is correct
13 Correct 32 ms 87204 KB Output is correct
14 Correct 39 ms 87100 KB Output is correct
15 Correct 39 ms 87132 KB Output is correct
16 Correct 34 ms 87200 KB Output is correct
17 Correct 32 ms 87144 KB Output is correct
18 Correct 32 ms 87204 KB Output is correct
19 Correct 32 ms 87160 KB Output is correct
20 Correct 32 ms 87116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 87188 KB Output is correct
2 Correct 33 ms 87104 KB Output is correct
3 Correct 33 ms 87108 KB Output is correct
4 Correct 34 ms 87216 KB Output is correct
5 Correct 37 ms 87108 KB Output is correct
6 Correct 31 ms 87136 KB Output is correct
7 Correct 36 ms 87120 KB Output is correct
8 Correct 32 ms 87156 KB Output is correct
9 Correct 32 ms 87140 KB Output is correct
10 Correct 33 ms 87092 KB Output is correct
11 Correct 31 ms 87132 KB Output is correct
12 Correct 32 ms 87108 KB Output is correct
13 Correct 35 ms 87144 KB Output is correct
14 Correct 32 ms 87188 KB Output is correct
15 Correct 32 ms 87108 KB Output is correct
16 Correct 32 ms 87180 KB Output is correct
17 Correct 32 ms 87144 KB Output is correct
18 Correct 34 ms 87176 KB Output is correct
19 Correct 33 ms 87168 KB Output is correct
20 Correct 33 ms 87180 KB Output is correct
21 Correct 34 ms 87200 KB Output is correct
22 Correct 33 ms 87096 KB Output is correct
23 Correct 32 ms 87084 KB Output is correct
24 Correct 33 ms 87108 KB Output is correct
25 Correct 31 ms 87108 KB Output is correct
26 Correct 32 ms 87108 KB Output is correct
27 Correct 32 ms 87200 KB Output is correct
28 Correct 32 ms 87156 KB Output is correct
29 Correct 33 ms 87188 KB Output is correct
30 Correct 34 ms 87180 KB Output is correct
31 Correct 32 ms 87204 KB Output is correct
32 Correct 39 ms 87100 KB Output is correct
33 Correct 39 ms 87132 KB Output is correct
34 Correct 34 ms 87200 KB Output is correct
35 Correct 32 ms 87144 KB Output is correct
36 Correct 32 ms 87204 KB Output is correct
37 Correct 32 ms 87160 KB Output is correct
38 Correct 32 ms 87116 KB Output is correct
39 Correct 32 ms 87116 KB Output is correct
40 Correct 34 ms 87124 KB Output is correct
41 Correct 35 ms 87156 KB Output is correct
42 Correct 34 ms 87148 KB Output is correct
43 Correct 37 ms 87132 KB Output is correct
44 Correct 32 ms 87148 KB Output is correct
45 Correct 32 ms 87112 KB Output is correct
46 Correct 32 ms 87108 KB Output is correct
47 Correct 32 ms 87116 KB Output is correct
48 Correct 33 ms 87128 KB Output is correct
49 Correct 37 ms 87096 KB Output is correct
50 Correct 33 ms 87148 KB Output is correct
51 Correct 32 ms 87160 KB Output is correct
52 Correct 35 ms 87104 KB Output is correct
53 Correct 36 ms 87112 KB Output is correct
54 Correct 32 ms 87116 KB Output is correct
55 Correct 33 ms 87156 KB Output is correct
56 Correct 31 ms 87132 KB Output is correct
57 Correct 31 ms 87172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 87188 KB Output is correct
2 Correct 33 ms 87104 KB Output is correct
3 Correct 33 ms 87108 KB Output is correct
4 Correct 34 ms 87216 KB Output is correct
5 Correct 37 ms 87108 KB Output is correct
6 Correct 31 ms 87136 KB Output is correct
7 Correct 36 ms 87120 KB Output is correct
8 Correct 32 ms 87156 KB Output is correct
9 Correct 32 ms 87140 KB Output is correct
10 Correct 33 ms 87092 KB Output is correct
11 Correct 31 ms 87132 KB Output is correct
12 Correct 32 ms 87108 KB Output is correct
13 Correct 35 ms 87144 KB Output is correct
14 Correct 32 ms 87188 KB Output is correct
15 Correct 32 ms 87108 KB Output is correct
16 Correct 32 ms 87180 KB Output is correct
17 Correct 32 ms 87144 KB Output is correct
18 Correct 34 ms 87176 KB Output is correct
19 Correct 33 ms 87168 KB Output is correct
20 Correct 33 ms 87180 KB Output is correct
21 Correct 34 ms 87200 KB Output is correct
22 Correct 33 ms 87096 KB Output is correct
23 Correct 32 ms 87084 KB Output is correct
24 Correct 33 ms 87108 KB Output is correct
25 Correct 31 ms 87108 KB Output is correct
26 Correct 32 ms 87108 KB Output is correct
27 Correct 32 ms 87200 KB Output is correct
28 Correct 32 ms 87156 KB Output is correct
29 Correct 33 ms 87188 KB Output is correct
30 Correct 34 ms 87180 KB Output is correct
31 Correct 32 ms 87204 KB Output is correct
32 Correct 39 ms 87100 KB Output is correct
33 Correct 39 ms 87132 KB Output is correct
34 Correct 34 ms 87200 KB Output is correct
35 Correct 32 ms 87144 KB Output is correct
36 Correct 32 ms 87204 KB Output is correct
37 Correct 32 ms 87160 KB Output is correct
38 Correct 32 ms 87116 KB Output is correct
39 Correct 32 ms 87116 KB Output is correct
40 Correct 34 ms 87124 KB Output is correct
41 Correct 35 ms 87156 KB Output is correct
42 Correct 34 ms 87148 KB Output is correct
43 Correct 37 ms 87132 KB Output is correct
44 Correct 32 ms 87148 KB Output is correct
45 Correct 32 ms 87112 KB Output is correct
46 Correct 32 ms 87108 KB Output is correct
47 Correct 32 ms 87116 KB Output is correct
48 Correct 33 ms 87128 KB Output is correct
49 Correct 37 ms 87096 KB Output is correct
50 Correct 33 ms 87148 KB Output is correct
51 Correct 32 ms 87160 KB Output is correct
52 Correct 35 ms 87104 KB Output is correct
53 Correct 36 ms 87112 KB Output is correct
54 Correct 32 ms 87116 KB Output is correct
55 Correct 33 ms 87156 KB Output is correct
56 Correct 31 ms 87132 KB Output is correct
57 Correct 31 ms 87172 KB Output is correct
58 Correct 34 ms 87236 KB Output is correct
59 Correct 36 ms 87452 KB Output is correct
60 Correct 39 ms 87492 KB Output is correct
61 Correct 73 ms 87444 KB Output is correct
62 Correct 192 ms 87992 KB Output is correct
63 Correct 46 ms 87876 KB Output is correct
64 Correct 116 ms 87876 KB Output is correct
65 Correct 32 ms 87148 KB Output is correct
66 Correct 37 ms 87116 KB Output is correct
67 Correct 32 ms 87168 KB Output is correct
68 Correct 32 ms 87116 KB Output is correct
69 Correct 35 ms 87108 KB Output is correct
70 Correct 33 ms 87192 KB Output is correct
71 Correct 42 ms 87184 KB Output is correct
72 Correct 33 ms 87252 KB Output is correct
73 Correct 35 ms 87240 KB Output is correct
74 Correct 37 ms 87472 KB Output is correct
75 Correct 42 ms 87548 KB Output is correct
76 Correct 96 ms 87672 KB Output is correct
77 Correct 210 ms 87916 KB Output is correct
78 Correct 44 ms 87876 KB Output is correct
79 Correct 116 ms 87944 KB Output is correct
80 Correct 40 ms 87960 KB Output is correct
81 Correct 60 ms 87868 KB Output is correct
82 Correct 226 ms 87984 KB Output is correct
83 Correct 32 ms 87116 KB Output is correct
84 Correct 31 ms 87244 KB Output is correct
85 Correct 42 ms 87276 KB Output is correct
86 Correct 35 ms 87324 KB Output is correct
87 Correct 35 ms 87244 KB Output is correct
88 Correct 37 ms 87804 KB Output is correct
89 Correct 39 ms 87780 KB Output is correct
90 Correct 73 ms 87744 KB Output is correct
91 Correct 216 ms 88528 KB Output is correct
92 Correct 45 ms 88424 KB Output is correct
93 Correct 125 ms 88496 KB Output is correct
94 Correct 33 ms 87240 KB Output is correct
95 Correct 41 ms 87260 KB Output is correct
96 Correct 37 ms 87180 KB Output is correct
97 Correct 37 ms 87172 KB Output is correct
98 Correct 33 ms 87156 KB Output is correct
99 Correct 32 ms 87088 KB Output is correct