답안 #90666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90666 2018-12-23T12:13:43 Z P1QG K개의 묶음 (IZhO14_blocks) C++11
0 / 100
39 ms 41700 KB
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;

int n, k, a[maxn], F[maxn][105];

int main()
{
    //freopen("BLOCKS.inp","r",stdin);
    //freopen("BLOCKS.out","w",stdout);

    scanf("%d%d", &n, &k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d", &a[i]);
    }


    memset(F, 0x3f, sizeof(F));

    F[0][1] = 0;
    for(int i=1;i<=n;i++) F[i][1] = max(F[i-1][1], a[i]);

    for(int i=2;i<=k;i++)
    {
        stack< pair<int,int> > P;
        for(int j=i;j<=n;j++)
        {
            int cur = F[j-1][i-1];

            while(P.size() && a[P.top().second] <= a[j])
            {
                cur = min(cur, P.top().first);
                P.pop();
            }

            F[j][i] = min(cur + a[j], (P.size() == 0)?F[0][0]:F[P.top().second][i]);

            P.push( make_pair(cur, i));
        }
    }

    printf("%d", F[n][k]);
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:12: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:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 41464 KB Output is correct
2 Correct 29 ms 41468 KB Output is correct
3 Correct 29 ms 41528 KB Output is correct
4 Correct 30 ms 41648 KB Output is correct
5 Correct 29 ms 41648 KB Output is correct
6 Correct 29 ms 41648 KB Output is correct
7 Correct 29 ms 41648 KB Output is correct
8 Correct 29 ms 41648 KB Output is correct
9 Correct 30 ms 41652 KB Output is correct
10 Correct 30 ms 41668 KB Output is correct
11 Correct 29 ms 41668 KB Output is correct
12 Correct 29 ms 41668 KB Output is correct
13 Incorrect 29 ms 41668 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 41668 KB Output is correct
2 Correct 29 ms 41672 KB Output is correct
3 Correct 33 ms 41688 KB Output is correct
4 Correct 33 ms 41700 KB Output is correct
5 Correct 29 ms 41700 KB Output is correct
6 Correct 32 ms 41700 KB Output is correct
7 Correct 35 ms 41700 KB Output is correct
8 Correct 29 ms 41700 KB Output is correct
9 Correct 29 ms 41700 KB Output is correct
10 Correct 29 ms 41700 KB Output is correct
11 Correct 30 ms 41700 KB Output is correct
12 Correct 29 ms 41700 KB Output is correct
13 Correct 28 ms 41700 KB Output is correct
14 Incorrect 29 ms 41700 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 41700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 41700 KB Output isn't correct
2 Halted 0 ms 0 KB -