Submission #102762

# Submission time Handle Problem Language Result Execution time Memory
102762 2019-03-27T12:21:46 Z Mahmoud_Adel K blocks (IZhO14_blocks) C++14
0 / 100
46 ms 42548 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];
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 41464 KB Output is correct
2 Correct 40 ms 41464 KB Output is correct
3 Correct 40 ms 41472 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 34 ms 41464 KB Output is correct
6 Correct 37 ms 41468 KB Output is correct
7 Correct 39 ms 41464 KB Output is correct
8 Correct 34 ms 41464 KB Output is correct
9 Correct 34 ms 41464 KB Output is correct
10 Correct 34 ms 41592 KB Output is correct
11 Correct 42 ms 41464 KB Output is correct
12 Incorrect 38 ms 41464 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 41456 KB Output is correct
2 Correct 44 ms 41464 KB Output is correct
3 Correct 34 ms 41464 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 41 ms 41384 KB Output is correct
6 Correct 40 ms 41464 KB Output is correct
7 Correct 34 ms 41464 KB Output is correct
8 Correct 39 ms 41464 KB Output is correct
9 Correct 35 ms 41464 KB Output is correct
10 Correct 36 ms 41444 KB Output is correct
11 Correct 34 ms 41464 KB Output is correct
12 Correct 35 ms 41464 KB Output is correct
13 Correct 40 ms 41592 KB Output is correct
14 Incorrect 34 ms 41464 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 41720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 42548 KB Output isn't correct
2 Halted 0 ms 0 KB -