Submission #83389

# Submission time Handle Problem Language Result Execution time Memory
83389 2018-11-07T13:35:16 Z ToadDaveski K blocks (IZhO14_blocks) C++14
100 / 100
304 ms 89040 KB
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
using namespace std;
deque <pair <ll,ll> > v;
ll dp[101][100001],a[100001];
int main()
{
    ll n,k,i,j;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=0;i<=n;i++)
        for(j=0;j<=k;j++)
            dp[j][i]=1e9;
    dp[0][0]=0;
    for(i=1;i<=k;i++)
    {
        v.clear();
        for(j=1;j<=n;j++)
        {
            ll s=dp[i-1][j-1];
            if (j<i)
            {
                dp[i][j]=1e9;
                continue;
            }
            while(!v.empty() && v.front().fr<=a[j])
            {
                //cout<<v.front().first<<" delete "<<v.front().sc<<endl;
                s=min(s,v.front().sc);
                v.pop_front();
            }
            if (!v.empty() && v.front().fr+v.front().sc<=s+a[j])
            dp[i][j]=v.front().fr+v.front().sc;
            else
            {
                dp[i][j]=s+a[j];
                v.push_front({a[j],s});
                //cout<<v.front().first<<" add "<<v.front().sc<<endl;
            }
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    cout<<dp[k][n];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 2 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 736 KB Output is correct
16 Correct 2 ms 736 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 3 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 736 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 KB Output is correct
4 Correct 2 ms 736 KB Output is correct
5 Correct 2 ms 736 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 2 ms 736 KB Output is correct
8 Correct 3 ms 736 KB Output is correct
9 Correct 2 ms 804 KB Output is correct
10 Correct 2 ms 804 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 2 ms 804 KB Output is correct
14 Correct 2 ms 804 KB Output is correct
15 Correct 2 ms 804 KB Output is correct
16 Correct 2 ms 804 KB Output is correct
17 Correct 3 ms 804 KB Output is correct
18 Correct 3 ms 804 KB Output is correct
19 Correct 2 ms 804 KB Output is correct
20 Correct 2 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1028 KB Output is correct
2 Correct 2 ms 1028 KB Output is correct
3 Correct 2 ms 1028 KB Output is correct
4 Correct 2 ms 1028 KB Output is correct
5 Correct 3 ms 1028 KB Output is correct
6 Correct 2 ms 1028 KB Output is correct
7 Correct 2 ms 1028 KB Output is correct
8 Correct 2 ms 1028 KB Output is correct
9 Correct 2 ms 1028 KB Output is correct
10 Correct 2 ms 1028 KB Output is correct
11 Correct 3 ms 1028 KB Output is correct
12 Correct 2 ms 1028 KB Output is correct
13 Correct 2 ms 1028 KB Output is correct
14 Correct 2 ms 1028 KB Output is correct
15 Correct 3 ms 1336 KB Output is correct
16 Correct 3 ms 1340 KB Output is correct
17 Correct 3 ms 1340 KB Output is correct
18 Correct 3 ms 1348 KB Output is correct
19 Correct 3 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3020 KB Output is correct
2 Correct 20 ms 3020 KB Output is correct
3 Correct 26 ms 3916 KB Output is correct
4 Correct 86 ms 28236 KB Output is correct
5 Correct 262 ms 80680 KB Output is correct
6 Correct 52 ms 80680 KB Output is correct
7 Correct 144 ms 80680 KB Output is correct
8 Correct 2 ms 80680 KB Output is correct
9 Correct 3 ms 80680 KB Output is correct
10 Correct 2 ms 80680 KB Output is correct
11 Correct 2 ms 80680 KB Output is correct
12 Correct 2 ms 80680 KB Output is correct
13 Correct 3 ms 80680 KB Output is correct
14 Correct 24 ms 80680 KB Output is correct
15 Correct 6 ms 80680 KB Output is correct
16 Correct 10 ms 80680 KB Output is correct
17 Correct 20 ms 80680 KB Output is correct
18 Correct 24 ms 80680 KB Output is correct
19 Correct 84 ms 80680 KB Output is correct
20 Correct 209 ms 83048 KB Output is correct
21 Correct 51 ms 83048 KB Output is correct
22 Correct 116 ms 83048 KB Output is correct
23 Correct 42 ms 83048 KB Output is correct
24 Correct 57 ms 83048 KB Output is correct
25 Correct 209 ms 86444 KB Output is correct
26 Correct 2 ms 86444 KB Output is correct
27 Correct 3 ms 86444 KB Output is correct
28 Correct 29 ms 86444 KB Output is correct
29 Correct 6 ms 86444 KB Output is correct
30 Correct 11 ms 86444 KB Output is correct
31 Correct 33 ms 86444 KB Output is correct
32 Correct 41 ms 86444 KB Output is correct
33 Correct 112 ms 86444 KB Output is correct
34 Correct 304 ms 89040 KB Output is correct
35 Correct 46 ms 89040 KB Output is correct
36 Correct 143 ms 89040 KB Output is correct
37 Correct 7 ms 89040 KB Output is correct
38 Correct 24 ms 89040 KB Output is correct
39 Correct 3 ms 89040 KB Output is correct
40 Correct 2 ms 89040 KB Output is correct
41 Correct 2 ms 89040 KB Output is correct
42 Correct 2 ms 89040 KB Output is correct