답안 #167358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167358 2019-12-07T15:29:47 Z muhammad_hokimiyon K개의 묶음 (IZhO14_blocks) C++14
0 / 100
4 ms 504 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e3 + 7;
const int mod = 1e9 + 7;

int n,k;
int a[N];
int d[N][N];

void solve()
{
    cin >> n >> k;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
        d[1][i] = a[i];
    }
    for( int i = 1; i <= n; i++ ){
        for( int j = 1; j <= n; j++ ){
            d[i][j] = 1e9;
        }
    }
    for( int i = 1; i <= n; i++ ){
        for( int j = 1; j <= k; j++ ){
            int sum = 0;
            for( int h = i; h >= j; h-- ){
                sum = max( sum , a[h] );
                d[i][j] = min( d[h - 1][j - 1] + sum , d[i][j] );
            }
        }
    }
    cout << d[n][k];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );
    freopen( "blocks.in" , "r" , stdin );
    freopen( "blocks.out" , "w" , stdout );

    int t = 1;//cin >> t;
    while( t-- ){
        solve();
    }
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen( "blocks.in" , "r" , stdin );
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen( "blocks.out" , "w" , stdout );
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -