Submission #242063

# Submission time Handle Problem Language Result Execution time Memory
242063 2020-06-26T16:10:12 Z przxct K blocks (IZhO14_blocks) C++17
100 / 100
364 ms 80548 KB
#include <bits/stdc++.h>
#define fto(i,j,h)      for (int i=j; i<=h; ++i)
#define fdto(i,j,h)     for (int i=j; i>=h; --i)
#define przxct "main"
#define maxn 100003
#define fi first
#define se second
#define ll long long
#define db double
#define pi 3.141592653589

using namespace std;

int n, k, a[maxn];
ll F[103][maxn];
stack<int> t;
stack<pair<int, ll> > t2;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //#ifndef ONLINE_JUDGE
    //freopen(przxct".inp", "r", stdin);
    //freopen(przxct".out", "w", stdout);
    //#endif // ONLINE_JUDGE
    cin >> n >> k;
    fto(i,1,n)      cin >> a[i];
    int Max = 0;
    fto(i,1,n){
       Max = max(Max, a[i]);
       F[1][i] = Max;
    }
    fto(i,2,k)
      fto(j,1,n){
         F[i][j] = 1e18;
      }
    fto(g,2,k){
      t2.push({g-1, F[g-1][g-1]});
      fto(i,g,n){
         while (t.empty() == false && a[t.top()] < a[i]){
             t.pop();
         }
         if (t.empty() == false)   F[g][i] = min(F[g][i], F[g][t.top()]);
         t.push(i);
         ll Min = 1e18;
         while (t2.empty() == false && a[t2.top().fi] <= a[i]){
            Min = min(Min, min(t2.top().se, F[g-1][t2.top().fi]));
            t2.pop();
         }
         if (t2.empty() == false)    Min = min(Min, F[g-1][t2.top().fi]);
         F[g][i] = min(F[g][i], Min + a[i]);
         t2.push({i, Min});
      }
      while (t.empty() == false)     t.pop();
      while (t2.empty() == false)    t2.pop();
    }
    cout << F[k][n];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 640 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2560 KB Output is correct
2 Correct 10 ms 1152 KB Output is correct
3 Correct 17 ms 3328 KB Output is correct
4 Correct 93 ms 27648 KB Output is correct
5 Correct 267 ms 79736 KB Output is correct
6 Correct 24 ms 3712 KB Output is correct
7 Correct 126 ms 36608 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 40 ms 8832 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 15 ms 2560 KB Output is correct
17 Correct 11 ms 1152 KB Output is correct
18 Correct 18 ms 3328 KB Output is correct
19 Correct 123 ms 27768 KB Output is correct
20 Correct 332 ms 79736 KB Output is correct
21 Correct 23 ms 3704 KB Output is correct
22 Correct 161 ms 36608 KB Output is correct
23 Correct 16 ms 2176 KB Output is correct
24 Correct 47 ms 9216 KB Output is correct
25 Correct 364 ms 79736 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 37 ms 8832 KB Output is correct
29 Correct 6 ms 640 KB Output is correct
30 Correct 15 ms 2560 KB Output is correct
31 Correct 10 ms 1152 KB Output is correct
32 Correct 18 ms 3584 KB Output is correct
33 Correct 112 ms 28048 KB Output is correct
34 Correct 311 ms 80548 KB Output is correct
35 Correct 23 ms 4480 KB Output is correct
36 Correct 157 ms 37492 KB Output is correct
37 Correct 6 ms 632 KB Output is correct
38 Correct 31 ms 8832 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct