Submission #167359

# Submission time Handle Problem Language Result Execution time Memory
167359 2019-12-07T15:43:14 Z muhammad_hokimiyon K blocks (IZhO14_blocks) C++14
53 / 100
17 ms 764 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;
    int mx = 0;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
        mx = max( mx , a[i] );
        d[1][i] = mx;
    }
    for( int i = 2; i <= k; i++ ){
        for( int j = 1; j <= n; j++ ){
            d[i][j] = 1e9;
        }
    }
     for( int i = 2; i <= n; i++ ){
        for( int j = 2; j <= k; j++ ){
            int sum = 0;
            for( int h = i; h <= n; h++ ){
                sum = max( sum , a[h] );
                d[j][h] = min( d[j - 1][i - 1] + sum , d[j][h] );
            }
        }
    }
    /*
    for( int i = 2; i <= k; i++ ){
        for( int j = i; j <= n; j++ ){
            int mx = 0;
            for( int h = j; h <= n; h++ ){
                mx = max( mx , a[h] );
                d[i][h] = min( d[i][h] , d[i - 1][j - 1] + mx );
            }
        }
    }
    */
    cout << d[k][n];
}

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

    int t = 1;//cin >> t;
    while( t-- ){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 17 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 416 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 3 ms 760 KB Output is correct
17 Correct 3 ms 636 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -