Submission #173033

# Submission time Handle Problem Language Result Execution time Memory
173033 2020-01-03T06:15:08 Z juggernaut K blocks (IZhO14_blocks) C++14
100 / 100
269 ms 40712 KB
//Just try and the idea will come!
#include<bits/stdc++.h>
using namespace std;
int dp[101][100001],n,k,i,a[100001],j,tmp;
main(){
    scanf("%d%d",&n,&k);
    for(i=0;i<101;i++)
        for(j=0;j<100001;j++)dp[i][j]=1e8;
    dp[1][0]=0;
    for(i=1;i<=n;i++)scanf("%d",&a[i]),dp[1][i]=max(dp[1][i-1],a[i]);
    dp[1][0]=1e8;
    for(i=2;i<=k;i++){
        stack<pair<int,int>>st;
        for(j=i;j<=n;j++){
            tmp=dp[i-1][j-1];
            while(!st.empty()&&a[st.top().first]<a[j]){
                tmp=min(tmp,st.top().second);
                st.pop();
            }
            if(!st.empty()&&j>=i)dp[i][j]=dp[i][st.top().first];
            st.push({j,min(dp[i-1][j],tmp)});
            if(j>=i)dp[i][j]=min(dp[i][j],tmp+a[j]);
        }
    }
    printf("%d",dp[k][n]);
}

Compilation message

blocks.cpp:5:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
blocks.cpp:10:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%d",&a[i]),dp[1][i]=max(dp[1][i-1],a[i]);
                      ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39928 KB Output is correct
2 Correct 36 ms 39928 KB Output is correct
3 Correct 36 ms 39928 KB Output is correct
4 Correct 36 ms 39888 KB Output is correct
5 Correct 37 ms 39928 KB Output is correct
6 Correct 37 ms 39928 KB Output is correct
7 Correct 41 ms 39928 KB Output is correct
8 Correct 37 ms 39844 KB Output is correct
9 Correct 36 ms 39804 KB Output is correct
10 Correct 37 ms 39928 KB Output is correct
11 Correct 37 ms 39804 KB Output is correct
12 Correct 37 ms 39800 KB Output is correct
13 Correct 36 ms 39892 KB Output is correct
14 Correct 36 ms 39804 KB Output is correct
15 Correct 36 ms 39800 KB Output is correct
16 Correct 36 ms 39800 KB Output is correct
17 Correct 37 ms 39928 KB Output is correct
18 Correct 36 ms 39928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39800 KB Output is correct
2 Correct 36 ms 39868 KB Output is correct
3 Correct 37 ms 39928 KB Output is correct
4 Correct 36 ms 39800 KB Output is correct
5 Correct 36 ms 39804 KB Output is correct
6 Correct 37 ms 39928 KB Output is correct
7 Correct 36 ms 39800 KB Output is correct
8 Correct 36 ms 39928 KB Output is correct
9 Correct 38 ms 39844 KB Output is correct
10 Correct 42 ms 39800 KB Output is correct
11 Correct 37 ms 39928 KB Output is correct
12 Correct 36 ms 39800 KB Output is correct
13 Correct 37 ms 39900 KB Output is correct
14 Correct 37 ms 39800 KB Output is correct
15 Correct 37 ms 39868 KB Output is correct
16 Correct 40 ms 39928 KB Output is correct
17 Correct 37 ms 39928 KB Output is correct
18 Correct 36 ms 39800 KB Output is correct
19 Correct 36 ms 39800 KB Output is correct
20 Correct 37 ms 39800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 39920 KB Output is correct
2 Correct 36 ms 39928 KB Output is correct
3 Correct 37 ms 39800 KB Output is correct
4 Correct 36 ms 39796 KB Output is correct
5 Correct 36 ms 39928 KB Output is correct
6 Correct 37 ms 39836 KB Output is correct
7 Correct 36 ms 39928 KB Output is correct
8 Correct 37 ms 39800 KB Output is correct
9 Correct 37 ms 39900 KB Output is correct
10 Correct 37 ms 39928 KB Output is correct
11 Correct 37 ms 39928 KB Output is correct
12 Correct 37 ms 39868 KB Output is correct
13 Correct 40 ms 39928 KB Output is correct
14 Correct 36 ms 39800 KB Output is correct
15 Correct 37 ms 39800 KB Output is correct
16 Correct 38 ms 39928 KB Output is correct
17 Correct 37 ms 39928 KB Output is correct
18 Correct 36 ms 39932 KB Output is correct
19 Correct 36 ms 39928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 39968 KB Output is correct
2 Correct 42 ms 40056 KB Output is correct
3 Correct 47 ms 40056 KB Output is correct
4 Correct 98 ms 40028 KB Output is correct
5 Correct 207 ms 40440 KB Output is correct
6 Correct 53 ms 40316 KB Output is correct
7 Correct 122 ms 40312 KB Output is correct
8 Correct 36 ms 39800 KB Output is correct
9 Correct 36 ms 39928 KB Output is correct
10 Correct 37 ms 39836 KB Output is correct
11 Correct 37 ms 39800 KB Output is correct
12 Correct 37 ms 39800 KB Output is correct
13 Correct 37 ms 39800 KB Output is correct
14 Correct 59 ms 40056 KB Output is correct
15 Correct 38 ms 39928 KB Output is correct
16 Correct 43 ms 39928 KB Output is correct
17 Correct 43 ms 40056 KB Output is correct
18 Correct 49 ms 40056 KB Output is correct
19 Correct 115 ms 40056 KB Output is correct
20 Correct 269 ms 40312 KB Output is correct
21 Correct 56 ms 40184 KB Output is correct
22 Correct 149 ms 40320 KB Output is correct
23 Correct 60 ms 40312 KB Output is correct
24 Correct 71 ms 40284 KB Output is correct
25 Correct 264 ms 40372 KB Output is correct
26 Correct 37 ms 39928 KB Output is correct
27 Correct 37 ms 39928 KB Output is correct
28 Correct 55 ms 39988 KB Output is correct
29 Correct 38 ms 39928 KB Output is correct
30 Correct 42 ms 39928 KB Output is correct
31 Correct 42 ms 40056 KB Output is correct
32 Correct 48 ms 40332 KB Output is correct
33 Correct 103 ms 40348 KB Output is correct
34 Correct 235 ms 40664 KB Output is correct
35 Correct 53 ms 40712 KB Output is correct
36 Correct 133 ms 40652 KB Output is correct
37 Correct 38 ms 39928 KB Output is correct
38 Correct 53 ms 39928 KB Output is correct
39 Correct 37 ms 39800 KB Output is correct
40 Correct 37 ms 39900 KB Output is correct
41 Correct 37 ms 39928 KB Output is correct
42 Correct 36 ms 39932 KB Output is correct