Submission #1077887

# Submission time Handle Problem Language Result Execution time Memory
1077887 2024-08-27T10:08:10 Z ntdaccode K blocks (IZhO14_blocks) C++17
100 / 100
185 ms 88468 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
int n,k,f[100010][110],a[100010];
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> k;
  fori(i,1,n) cin >> a[i];
  memset(f,61,sizeof(f));
  f[0][1]=0;
  fori(i,1,n) f[i][1]=max(f[i-1][1],a[i]);
  f[0][1]=1e16;
  fori(j,2,k)
  {
    stack<int> sk;
    fori(i,1,n)
    {
      while(!sk.empty()&&a[sk.top()]<=a[i])
      {
        f[i][j]=min(f[i][j],f[sk.top()][j-1]+a[i]);
        f[i][j]=min(f[i][j],f[sk.top()][j]+a[i]-a[sk.top()]);
        sk.pop();
      }
      if(sk.size())
      {
        f[i][j]=min(f[i][j],f[sk.top()][j-1]+a[i]);
        f[i][j]=min(f[i][j],f[sk.top()][j]);
        
      }
      sk.push(i);
    }
  }
  cout << f[n][k];
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 86356 KB Output is correct
2 Correct 44 ms 86364 KB Output is correct
3 Correct 42 ms 86356 KB Output is correct
4 Correct 42 ms 86324 KB Output is correct
5 Correct 42 ms 86352 KB Output is correct
6 Correct 42 ms 86356 KB Output is correct
7 Correct 52 ms 86356 KB Output is correct
8 Correct 49 ms 86356 KB Output is correct
9 Correct 42 ms 86336 KB Output is correct
10 Correct 41 ms 86356 KB Output is correct
11 Correct 44 ms 86360 KB Output is correct
12 Correct 42 ms 86356 KB Output is correct
13 Correct 43 ms 86352 KB Output is correct
14 Correct 41 ms 86368 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 43 ms 86360 KB Output is correct
17 Correct 41 ms 86348 KB Output is correct
18 Correct 41 ms 86560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 86352 KB Output is correct
2 Correct 41 ms 86352 KB Output is correct
3 Correct 40 ms 86508 KB Output is correct
4 Correct 41 ms 86352 KB Output is correct
5 Correct 41 ms 86356 KB Output is correct
6 Correct 48 ms 86356 KB Output is correct
7 Correct 43 ms 86340 KB Output is correct
8 Correct 36 ms 86460 KB Output is correct
9 Correct 48 ms 86384 KB Output is correct
10 Correct 41 ms 86352 KB Output is correct
11 Correct 44 ms 86356 KB Output is correct
12 Correct 41 ms 86352 KB Output is correct
13 Correct 42 ms 86352 KB Output is correct
14 Correct 44 ms 86548 KB Output is correct
15 Correct 48 ms 86352 KB Output is correct
16 Correct 44 ms 86352 KB Output is correct
17 Correct 45 ms 86352 KB Output is correct
18 Correct 41 ms 86352 KB Output is correct
19 Correct 47 ms 86316 KB Output is correct
20 Correct 44 ms 86356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 86356 KB Output is correct
2 Correct 44 ms 86364 KB Output is correct
3 Correct 42 ms 86356 KB Output is correct
4 Correct 42 ms 86324 KB Output is correct
5 Correct 42 ms 86352 KB Output is correct
6 Correct 42 ms 86356 KB Output is correct
7 Correct 52 ms 86356 KB Output is correct
8 Correct 49 ms 86356 KB Output is correct
9 Correct 42 ms 86336 KB Output is correct
10 Correct 41 ms 86356 KB Output is correct
11 Correct 44 ms 86360 KB Output is correct
12 Correct 42 ms 86356 KB Output is correct
13 Correct 43 ms 86352 KB Output is correct
14 Correct 41 ms 86368 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 43 ms 86360 KB Output is correct
17 Correct 41 ms 86348 KB Output is correct
18 Correct 41 ms 86560 KB Output is correct
19 Correct 50 ms 86352 KB Output is correct
20 Correct 41 ms 86352 KB Output is correct
21 Correct 40 ms 86508 KB Output is correct
22 Correct 41 ms 86352 KB Output is correct
23 Correct 41 ms 86356 KB Output is correct
24 Correct 48 ms 86356 KB Output is correct
25 Correct 43 ms 86340 KB Output is correct
26 Correct 36 ms 86460 KB Output is correct
27 Correct 48 ms 86384 KB Output is correct
28 Correct 41 ms 86352 KB Output is correct
29 Correct 44 ms 86356 KB Output is correct
30 Correct 41 ms 86352 KB Output is correct
31 Correct 42 ms 86352 KB Output is correct
32 Correct 44 ms 86548 KB Output is correct
33 Correct 48 ms 86352 KB Output is correct
34 Correct 44 ms 86352 KB Output is correct
35 Correct 45 ms 86352 KB Output is correct
36 Correct 41 ms 86352 KB Output is correct
37 Correct 47 ms 86316 KB Output is correct
38 Correct 44 ms 86356 KB Output is correct
39 Correct 42 ms 86472 KB Output is correct
40 Correct 49 ms 86356 KB Output is correct
41 Correct 44 ms 86348 KB Output is correct
42 Correct 40 ms 86356 KB Output is correct
43 Correct 41 ms 86328 KB Output is correct
44 Correct 43 ms 86508 KB Output is correct
45 Correct 44 ms 86352 KB Output is correct
46 Correct 46 ms 86484 KB Output is correct
47 Correct 38 ms 86504 KB Output is correct
48 Correct 42 ms 86356 KB Output is correct
49 Correct 42 ms 86352 KB Output is correct
50 Correct 40 ms 86352 KB Output is correct
51 Correct 38 ms 86548 KB Output is correct
52 Correct 43 ms 86560 KB Output is correct
53 Correct 43 ms 86356 KB Output is correct
54 Correct 52 ms 86352 KB Output is correct
55 Correct 47 ms 86352 KB Output is correct
56 Correct 41 ms 86500 KB Output is correct
57 Correct 42 ms 86468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 86356 KB Output is correct
2 Correct 44 ms 86364 KB Output is correct
3 Correct 42 ms 86356 KB Output is correct
4 Correct 42 ms 86324 KB Output is correct
5 Correct 42 ms 86352 KB Output is correct
6 Correct 42 ms 86356 KB Output is correct
7 Correct 52 ms 86356 KB Output is correct
8 Correct 49 ms 86356 KB Output is correct
9 Correct 42 ms 86336 KB Output is correct
10 Correct 41 ms 86356 KB Output is correct
11 Correct 44 ms 86360 KB Output is correct
12 Correct 42 ms 86356 KB Output is correct
13 Correct 43 ms 86352 KB Output is correct
14 Correct 41 ms 86368 KB Output is correct
15 Correct 43 ms 86356 KB Output is correct
16 Correct 43 ms 86360 KB Output is correct
17 Correct 41 ms 86348 KB Output is correct
18 Correct 41 ms 86560 KB Output is correct
19 Correct 50 ms 86352 KB Output is correct
20 Correct 41 ms 86352 KB Output is correct
21 Correct 40 ms 86508 KB Output is correct
22 Correct 41 ms 86352 KB Output is correct
23 Correct 41 ms 86356 KB Output is correct
24 Correct 48 ms 86356 KB Output is correct
25 Correct 43 ms 86340 KB Output is correct
26 Correct 36 ms 86460 KB Output is correct
27 Correct 48 ms 86384 KB Output is correct
28 Correct 41 ms 86352 KB Output is correct
29 Correct 44 ms 86356 KB Output is correct
30 Correct 41 ms 86352 KB Output is correct
31 Correct 42 ms 86352 KB Output is correct
32 Correct 44 ms 86548 KB Output is correct
33 Correct 48 ms 86352 KB Output is correct
34 Correct 44 ms 86352 KB Output is correct
35 Correct 45 ms 86352 KB Output is correct
36 Correct 41 ms 86352 KB Output is correct
37 Correct 47 ms 86316 KB Output is correct
38 Correct 44 ms 86356 KB Output is correct
39 Correct 42 ms 86472 KB Output is correct
40 Correct 49 ms 86356 KB Output is correct
41 Correct 44 ms 86348 KB Output is correct
42 Correct 40 ms 86356 KB Output is correct
43 Correct 41 ms 86328 KB Output is correct
44 Correct 43 ms 86508 KB Output is correct
45 Correct 44 ms 86352 KB Output is correct
46 Correct 46 ms 86484 KB Output is correct
47 Correct 38 ms 86504 KB Output is correct
48 Correct 42 ms 86356 KB Output is correct
49 Correct 42 ms 86352 KB Output is correct
50 Correct 40 ms 86352 KB Output is correct
51 Correct 38 ms 86548 KB Output is correct
52 Correct 43 ms 86560 KB Output is correct
53 Correct 43 ms 86356 KB Output is correct
54 Correct 52 ms 86352 KB Output is correct
55 Correct 47 ms 86352 KB Output is correct
56 Correct 41 ms 86500 KB Output is correct
57 Correct 42 ms 86468 KB Output is correct
58 Correct 44 ms 86620 KB Output is correct
59 Correct 45 ms 87124 KB Output is correct
60 Correct 52 ms 87016 KB Output is correct
61 Correct 84 ms 87120 KB Output is correct
62 Correct 167 ms 87888 KB Output is correct
63 Correct 56 ms 87900 KB Output is correct
64 Correct 102 ms 87892 KB Output is correct
65 Correct 42 ms 86356 KB Output is correct
66 Correct 44 ms 86412 KB Output is correct
67 Correct 42 ms 86356 KB Output is correct
68 Correct 41 ms 86352 KB Output is correct
69 Correct 41 ms 86356 KB Output is correct
70 Correct 42 ms 86472 KB Output is correct
71 Correct 54 ms 86612 KB Output is correct
72 Correct 43 ms 86456 KB Output is correct
73 Correct 46 ms 86608 KB Output is correct
74 Correct 47 ms 87096 KB Output is correct
75 Correct 49 ms 86976 KB Output is correct
76 Correct 93 ms 87120 KB Output is correct
77 Correct 185 ms 87864 KB Output is correct
78 Correct 54 ms 87984 KB Output is correct
79 Correct 117 ms 88008 KB Output is correct
80 Correct 56 ms 87888 KB Output is correct
81 Correct 66 ms 88144 KB Output is correct
82 Correct 182 ms 87888 KB Output is correct
83 Correct 43 ms 86352 KB Output is correct
84 Correct 42 ms 86504 KB Output is correct
85 Correct 52 ms 86608 KB Output is correct
86 Correct 50 ms 86612 KB Output is correct
87 Correct 46 ms 86572 KB Output is correct
88 Correct 45 ms 87124 KB Output is correct
89 Correct 63 ms 87180 KB Output is correct
90 Correct 85 ms 87124 KB Output is correct
91 Correct 183 ms 88468 KB Output is correct
92 Correct 51 ms 88252 KB Output is correct
93 Correct 105 ms 88308 KB Output is correct
94 Correct 41 ms 86612 KB Output is correct
95 Correct 60 ms 86608 KB Output is correct
96 Correct 42 ms 86352 KB Output is correct
97 Correct 52 ms 86352 KB Output is correct
98 Correct 43 ms 86512 KB Output is correct
99 Correct 43 ms 86360 KB Output is correct