답안 #168530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168530 2019-12-13T12:39:06 Z muhammad_hokimiyon K개의 묶음 (IZhO14_blocks) C++14
0 / 100
7 ms 1656 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 = 1e6 + 7;
const int mod = 1e9 + 7;

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

void solve()
{
    cin >> n >> k;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
        d[1][i] = max( d[1][i - 1] , a[i] );
    }
    for( int i = 2; i <= k; i++ ){
        d[i][i] = d[i - 1][i - 1] + a[i];
        stack < pair < int , int > > st;
        st.push({d[i - 1][i - 1] , a[i]});
        for( int j = i + 1; j <= n; j++ ){
            int cnt = d[i - 1][j - 1];
            while( !st.empty() && st.top().se <= a[j] ){
                cnt = min( cnt , st.top().fi );
                st.pop();
            }
            if( st.empty() || st.top().fi + st.top().se <= cnt + a[j] ){
                st.push({cnt , a[j]});
            }
            d[i][j] = st.top().fi + st.top().se;
        }
    }
    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();
    }
}
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 504 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -