답안 #395420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395420 2021-04-28T10:39:56 Z __algebra__ K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 208 KB
#include<bits/stdc++.h>
using namespace std;
int dp[100001][101],arr[100001];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<=k;++i)for(int j=0;j<=n;++j)dp[j][i]=1e9;
    dp[0][1]=0;
    for(int i=1;i<=n;i++)scanf("%d",&arr[i]),dp[i][1]=max(dp[i-1][1],arr[i]);
    for(int j=2;j<=k;++j){
        stack<pair<int,int>>stk;
        for(int i=j;i<=n;++i){
            int dpi=dp[i-1][j-1] , ai = arr[i];
            while(!stk.empty() && stk.top().second <= ai)dpi=min(dpi,stk.top().first),stk.pop();
            if(stk.empty() || stk.top().first+stk.top().second > ai+dpi) stk.push({dpi,ai});
            dp[i][k]=stk.top().first+stk.top().second;
        }
    }
    printf("%d\n",dp[n][k]);
}

Compilation message

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]
    6 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
blocks.cpp:9:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     for(int i=1;i<=n;i++)scanf("%d",&arr[i]),dp[i][1]=max(dp[i-1][1],arr[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Halted 0 ms 0 KB -