답안 #547310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547310 2022-04-10T10:30:45 Z krit3379 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define N 100005

int a[N],l[N],dp[105][N];

int main(){
    int n,k,i,j;
    scanf("%d %d",&n,&k);
    a[0]=2e9;
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        l[i]=i-1;
        while(a[i]>a[l[i]])l[i]=l[l[i]];
    }
    for(i=0;i<=k;i++)for(j=0;j<=n;j++)dp[i][j]=1e9;
    for(i=1;i<=n;i++){
        if(l[i]==0)dp[1][i]=a[i];
        dp[1][i]=min(dp[1][i],dp[1][l[i]]);
    }
    for(i=2;i<=k;i++){
        for(j=i;j<=n;j++){
            dp[i][j]=min({dp[i][j],dp[i][l[j]],dp[i-1][l[j]+1]+a[j],dp[i-1][j-1]+a[j]});
        }
    }
    printf("%d",dp[k][n]);
    return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
blocks.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 224 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Incorrect 1 ms 308 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 224 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 224 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -