답안 #102742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102742 2019-03-27T11:22:07 Z Mahmoud_Adel K개의 묶음 (IZhO14_blocks) C++14
0 / 100
43 ms 41592 KB
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
typedef long long ll;
const int N = 100005, M = 105;
int n, k, a[N], dp[N][M], ch[N][M];
int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    memset(dp, 0x3f3f3f3f, sizeof dp);
    dp[0][0] = 0;
    for(int i=1; i<=k; i++)
    {
        stack<int> s;
        for(int j=1; j<=n; j++)
        {
            dp[i][j] = dp[i-1][j-1]+ a[j], ch[i][j] = a[j];
            while(!s.empty())
            {
                int u = s.top();
                if(a[u] <= a[j])
                {
                    if(dp[i][j] > dp[i][u] - ch[i][u] + max(ch[i][u], a[j]))
                    dp[i][j] = dp[i][u] - ch[i][u] + max(ch[i][u], a[j]), ch[i][j] = max(ch[i][u], a[j]);
                }
                else break;
                s.pop();
            }
            if(!s.empty())
            {
                int u = s.top();
                if(dp[i][u] < dp[i][j])
                {
                    dp[i][j] = dp[i][u];
                    ch[i][j] = ch[i][u];
                }
            }
            s.push(i);
        }
    }
    cout << dp[k][n] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 41464 KB Output is correct
2 Correct 39 ms 41512 KB Output is correct
3 Correct 36 ms 41464 KB Output is correct
4 Correct 37 ms 41436 KB Output is correct
5 Correct 36 ms 41472 KB Output is correct
6 Correct 36 ms 41472 KB Output is correct
7 Correct 36 ms 41464 KB Output is correct
8 Correct 37 ms 41464 KB Output is correct
9 Correct 36 ms 41464 KB Output is correct
10 Correct 38 ms 41592 KB Output is correct
11 Correct 38 ms 41472 KB Output is correct
12 Incorrect 41 ms 41472 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 41464 KB Output is correct
2 Correct 35 ms 41428 KB Output is correct
3 Correct 37 ms 41420 KB Output is correct
4 Correct 42 ms 41464 KB Output is correct
5 Correct 37 ms 41464 KB Output is correct
6 Correct 36 ms 41464 KB Output is correct
7 Correct 35 ms 41472 KB Output is correct
8 Correct 36 ms 41464 KB Output is correct
9 Correct 39 ms 41464 KB Output is correct
10 Correct 40 ms 41468 KB Output is correct
11 Correct 36 ms 41464 KB Output is correct
12 Correct 36 ms 41464 KB Output is correct
13 Correct 43 ms 41464 KB Output is correct
14 Incorrect 34 ms 41464 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 41408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 41564 KB Output isn't correct
2 Halted 0 ms 0 KB -