Submission #96020

# Submission time Handle Problem Language Result Execution time Memory
96020 2019-02-05T09:23:01 Z Kastanda K blocks (IZhO14_blocks) C++11
100 / 100
118 ms 3064 KB
#include<bits/stdc++.h>
#define lc (id << 1)
#define rc (id << 1 ^ 1)
#define md ((l + r) >> 1)
using namespace std;
const int N = 100005, K = 104, INF = 30000 * 10000;
int n, k, A[N], dp[2][N], stk[N];
int mn[N], pref[N];
/*int mn[N * 4], lazy[N * 4];
int le, ri, val;
void Add(int id = 1, int l = 0, int r = n + 1)
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
    {
        lazy[id] += val;
        mn[id] += val;
        return ;
    }
    Add(lc, l, md);
    Add(rc, md, r);
    mn[id] = min(mn[lc], mn[rc]) + lazy[id];
}
int Get(int id = 1, int l = 0, int r = n + 1)
{
    if (ri <= l || r <= le)
        return (INF);
    if (le <= l && r <= ri)
        return (mn[id]);
    return (min(Get(lc, l, md), Get(rc, md, r)) + lazy[id]);
}
inline void Adder(int _le, int _ri, int _val) {le = _le; ri = _ri; val = _val; Add();}
inline int Getter(int _le, int _ri) {le = _le; ri = _ri; return (Get());}*/
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &A[i]);
        dp[0][i] = dp[1][i] = INF;
    }
    A[0] = dp[1][0] = INF;
    for (int j = 1; j <= k; j++)
    {
        int w = j & 1;
        int r = 1;
        memset(mn, 0, sizeof(mn));
        //memset(lazy, 0, sizeof(lazy));
        //Adder(0, 1, dp[!w][0]);
        dp[w][0] = pref[0] = mn[0] = INF;
        for (int i = 1; i <= n; i++)
        {
            mn[i] = dp[!w][i - 1] + A[i];
            while (A[stk[r]] <= A[i])
                mn[i] = min(mn[i], mn[stk[r]] + A[i] - A[stk[r]]), r --;
                //Adder(stk[r - 1], stk[r], A[i] - A[stk[r]]), r --;
            pref[i] = min(pref[stk[r]], mn[i]);
            stk[++ r] = i;
            dp[w][i] = pref[i];
            //Adder(i - 1, i, A[i]);
            //dp[w][i] = Getter(0, i);
            //Adder(i, i + 1, dp[!w][i]);
        }
    }
    return !printf("%d\n", dp[k & 1][n]);
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 764 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 808 KB Output is correct
16 Correct 2 ms 764 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 764 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 5 ms 760 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 8 ms 1400 KB Output is correct
3 Correct 10 ms 1400 KB Output is correct
4 Correct 37 ms 1468 KB Output is correct
5 Correct 99 ms 2936 KB Output is correct
6 Correct 17 ms 2936 KB Output is correct
7 Correct 51 ms 3064 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 14 ms 1016 KB Output is correct
15 Correct 4 ms 888 KB Output is correct
16 Correct 6 ms 1016 KB Output is correct
17 Correct 8 ms 1716 KB Output is correct
18 Correct 12 ms 1784 KB Output is correct
19 Correct 44 ms 1784 KB Output is correct
20 Correct 118 ms 3064 KB Output is correct
21 Correct 24 ms 3064 KB Output is correct
22 Correct 63 ms 2936 KB Output is correct
23 Correct 16 ms 2956 KB Output is correct
24 Correct 25 ms 2940 KB Output is correct
25 Correct 118 ms 2936 KB Output is correct
26 Correct 2 ms 732 KB Output is correct
27 Correct 2 ms 764 KB Output is correct
28 Correct 12 ms 1016 KB Output is correct
29 Correct 4 ms 1016 KB Output is correct
30 Correct 6 ms 1016 KB Output is correct
31 Correct 8 ms 1784 KB Output is correct
32 Correct 10 ms 1780 KB Output is correct
33 Correct 35 ms 1784 KB Output is correct
34 Correct 92 ms 3064 KB Output is correct
35 Correct 16 ms 3064 KB Output is correct
36 Correct 49 ms 3064 KB Output is correct
37 Correct 4 ms 1016 KB Output is correct
38 Correct 12 ms 1016 KB Output is correct
39 Correct 2 ms 760 KB Output is correct
40 Correct 2 ms 760 KB Output is correct
41 Correct 2 ms 760 KB Output is correct
42 Correct 2 ms 760 KB Output is correct