답안 #102771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102771 2019-03-27T12:51:51 Z Mahmoud_Adel K개의 묶음 (IZhO14_blocks) C++14
0 / 100
9 ms 2688 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[M][N], ch[M][N];
int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    dp[0][1] = 0;
    for(int i=1; i<=n; i++) dp[1][i] = max(dp[1][i-1], a[i]), ch[1][i] = dp[1][i];
    for(int i=2; i<=k; i++)
    {
        stack<int> s;
        for(int j=i; 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]);
                }
                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 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 3 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Incorrect 2 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -