Submission #413214

# Submission time Handle Problem Language Result Execution time Memory
413214 2021-05-28T11:21:00 Z LptN21 K blocks (IZhO14_blocks) C++14
100 / 100
295 ms 43528 KB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define FF first
#define SS second
#define pb push_back
#define sz(x) (int)x.size()
#define oo 1e9
#define PI acos(-1.0)
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
const int N = 100000+7, M=100+7;
const ll MOD = 1e9+7;

int n, m, k, t;

int a[N], _dp[N][M];

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;scanf("%d", &a[i++]))
        for(int j=0;j<=m;j++) _dp[i][j]=oo;
    for(int i=0;i<=m;i++) _dp[0][i]=oo;_dp[0][1]=0;
    for(int i=1;i<=n;i++) _dp[i][1]=max(_dp[i-1][1], a[i]);
    for(int mn, j=2;j<=m;j++) {
        stack<ii> st;
        for(int i=j;i<=n;i++) {
            mn=_dp[i-1][j-1];
            while(sz(st)&&a[st.top().SS]<=a[i])
                mn=min(st.top().FF, mn), st.pop();
            _dp[i][j]=min(_dp[sz(st)?st.top().SS:0][j], mn+a[i]);
            st.push(ii(mn, i));
        }
    }
    printf("%d", _dp[n][m]);
    return 0;
}
/* stuff you should look for
    - int overflow, array bounds
    - special cases (n=1?)
    - do smth instead of do nothing and stay organized
    - WRITE STUFF DOWN
    - DONT JUST STICK ON ONE APPROACH
*/

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:29:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   29 |     for(int i=0;i<=m;i++) _dp[0][i]=oo;_dp[0][1]=0;
      |     ^~~
blocks.cpp:29:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   29 |     for(int i=0;i<=m;i++) _dp[0][i]=oo;_dp[0][1]=0;
      |                                        ^~~
blocks.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:27:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     for(int i=1;i<=n;scanf("%d", &a[i++]))
      |                      ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 224 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 312 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 224 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 312 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 8 ms 4544 KB Output is correct
59 Correct 16 ms 19276 KB Output is correct
60 Correct 25 ms 19324 KB Output is correct
61 Correct 76 ms 19384 KB Output is correct
62 Correct 239 ms 43344 KB Output is correct
63 Correct 38 ms 43172 KB Output is correct
64 Correct 118 ms 43232 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 304 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 1 ms 700 KB Output is correct
70 Correct 1 ms 696 KB Output is correct
71 Correct 35 ms 4596 KB Output is correct
72 Correct 4 ms 4584 KB Output is correct
73 Correct 27 ms 4576 KB Output is correct
74 Correct 16 ms 19336 KB Output is correct
75 Correct 26 ms 19344 KB Output is correct
76 Correct 81 ms 19256 KB Output is correct
77 Correct 295 ms 43204 KB Output is correct
78 Correct 42 ms 43160 KB Output is correct
79 Correct 142 ms 43224 KB Output is correct
80 Correct 32 ms 43172 KB Output is correct
81 Correct 53 ms 43236 KB Output is correct
82 Correct 274 ms 43236 KB Output is correct
83 Correct 1 ms 692 KB Output is correct
84 Correct 1 ms 716 KB Output is correct
85 Correct 20 ms 4548 KB Output is correct
86 Correct 8 ms 4556 KB Output is correct
87 Correct 8 ms 4556 KB Output is correct
88 Correct 17 ms 19352 KB Output is correct
89 Correct 22 ms 19492 KB Output is correct
90 Correct 80 ms 19396 KB Output is correct
91 Correct 278 ms 43520 KB Output is correct
92 Correct 39 ms 43500 KB Output is correct
93 Correct 145 ms 43528 KB Output is correct
94 Correct 4 ms 4556 KB Output is correct
95 Correct 20 ms 4576 KB Output is correct
96 Correct 1 ms 716 KB Output is correct
97 Correct 1 ms 716 KB Output is correct
98 Correct 1 ms 312 KB Output is correct
99 Correct 1 ms 204 KB Output is correct