답안 #173032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173032 2020-01-03T06:14:30 Z juggernaut K개의 묶음 (IZhO14_blocks) C++14
100 / 100
270 ms 41484 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=1;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]);
                      ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 39800 KB Output is correct
2 Correct 37 ms 39800 KB Output is correct
3 Correct 36 ms 39800 KB Output is correct
4 Correct 37 ms 39800 KB Output is correct
5 Correct 37 ms 39928 KB Output is correct
6 Correct 37 ms 39800 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 39800 KB Output is correct
10 Correct 37 ms 39928 KB Output is correct
11 Correct 38 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 36 ms 39800 KB Output is correct
15 Correct 36 ms 39928 KB Output is correct
16 Correct 37 ms 39800 KB Output is correct
17 Correct 36 ms 39800 KB Output is correct
18 Correct 41 ms 39800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 39840 KB Output is correct
2 Correct 36 ms 39800 KB Output is correct
3 Correct 37 ms 39804 KB Output is correct
4 Correct 37 ms 39928 KB Output is correct
5 Correct 35 ms 39800 KB Output is correct
6 Correct 37 ms 39800 KB Output is correct
7 Correct 37 ms 39832 KB Output is correct
8 Correct 37 ms 39800 KB Output is correct
9 Correct 39 ms 39896 KB Output is correct
10 Correct 43 ms 39800 KB Output is correct
11 Correct 36 ms 39868 KB Output is correct
12 Correct 36 ms 39900 KB Output is correct
13 Correct 36 ms 39800 KB Output is correct
14 Correct 37 ms 39928 KB Output is correct
15 Correct 37 ms 40056 KB Output is correct
16 Correct 37 ms 39928 KB Output is correct
17 Correct 42 ms 39800 KB Output is correct
18 Correct 37 ms 39928 KB Output is correct
19 Correct 37 ms 39928 KB Output is correct
20 Correct 43 ms 39900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 39900 KB Output is correct
2 Correct 37 ms 39928 KB Output is correct
3 Correct 41 ms 39880 KB Output is correct
4 Correct 37 ms 39928 KB Output is correct
5 Correct 37 ms 39928 KB Output is correct
6 Correct 37 ms 39928 KB Output is correct
7 Correct 37 ms 39928 KB Output is correct
8 Correct 37 ms 39928 KB Output is correct
9 Correct 36 ms 39928 KB Output is correct
10 Correct 37 ms 39928 KB Output is correct
11 Correct 36 ms 39928 KB Output is correct
12 Correct 37 ms 39800 KB Output is correct
13 Correct 36 ms 39900 KB Output is correct
14 Correct 37 ms 39928 KB Output is correct
15 Correct 37 ms 39928 KB Output is correct
16 Correct 37 ms 39932 KB Output is correct
17 Correct 41 ms 39928 KB Output is correct
18 Correct 37 ms 39800 KB Output is correct
19 Correct 37 ms 39928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 39900 KB Output is correct
2 Correct 42 ms 40312 KB Output is correct
3 Correct 47 ms 40312 KB Output is correct
4 Correct 96 ms 40312 KB Output is correct
5 Correct 209 ms 40964 KB Output is correct
6 Correct 53 ms 40956 KB Output is correct
7 Correct 120 ms 40924 KB Output is correct
8 Correct 37 ms 39800 KB Output is correct
9 Correct 37 ms 39928 KB Output is correct
10 Correct 36 ms 39800 KB Output is correct
11 Correct 36 ms 39800 KB Output is correct
12 Correct 44 ms 39928 KB Output is correct
13 Correct 37 ms 39928 KB Output is correct
14 Correct 59 ms 40056 KB Output is correct
15 Correct 39 ms 40012 KB Output is correct
16 Correct 43 ms 39928 KB Output is correct
17 Correct 44 ms 40312 KB Output is correct
18 Correct 49 ms 40316 KB Output is correct
19 Correct 115 ms 40312 KB Output is correct
20 Correct 270 ms 40952 KB Output is correct
21 Correct 62 ms 40952 KB Output is correct
22 Correct 146 ms 40952 KB Output is correct
23 Correct 51 ms 40952 KB Output is correct
24 Correct 70 ms 40952 KB Output is correct
25 Correct 264 ms 40952 KB Output is correct
26 Correct 37 ms 39928 KB Output is correct
27 Correct 37 ms 39900 KB Output is correct
28 Correct 55 ms 40056 KB Output is correct
29 Correct 38 ms 40056 KB Output is correct
30 Correct 43 ms 40056 KB Output is correct
31 Correct 43 ms 40284 KB Output is correct
32 Correct 47 ms 40568 KB Output is correct
33 Correct 103 ms 40568 KB Output is correct
34 Correct 239 ms 41484 KB Output is correct
35 Correct 54 ms 41352 KB Output is correct
36 Correct 133 ms 41328 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 39800 KB Output is correct
41 Correct 37 ms 39800 KB Output is correct
42 Correct 36 ms 39800 KB Output is correct