Submission #635310

# Submission time Handle Problem Language Result Execution time Memory
635310 2022-08-26T04:05:40 Z ThMinh_ K blocks (IZhO14_blocks) C++14
53 / 100
87 ms 196856 KB
#include<bits/stdc++.h>
#define forin(i,a,b) for(int i=a;i<=b;++i)
#define forde(i,a,b) for(int i=a;i>=b;--i)
#define ll long long
using namespace std;
const int N = 5e3 + 10;
int n, k;
ll a[N], dp[N][N], sp[N][17];
void build() {
    forin(i,1,n) sp[i][0] = a[i];
    forin(j,1,log2(n)) forin(i,1,n - (1<<j) + 1) {
        sp[i][j] = max(sp[i][j - 1], sp[i + (1<<(j - 1))][j - 1]);
    }
}
ll cost(int f, int l) {
    if(f > l) return 1e16;
    int j = (int)log2(l - f + 1);
    return max(sp[f][j], sp[l - (1<<j) + 1][j]);
}
int main () {
    cin.tie(0)->sync_with_stdio(0);
    if(fopen("Task.inp","r")) {
        freopen("Task.inp","r",stdin);
        freopen("AC.out","w",stdout);
    }
    cin>>n>>k;
    forin(i,1,n) cin>>a[i];
    build();
    memset(dp, 127, sizeof(dp));
    dp[0][0] = 0;
    forin(o,1,k) forin(i,1,n) {
        ll &a = dp[i][o];
        forin(j,0,i - 1) {
            a = min(a, dp[j][o - 1] + cost(j + 1, i));
        }
    }
    cout<<dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("Task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen("AC.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 74 ms 196716 KB Output is correct
2 Correct 73 ms 196768 KB Output is correct
3 Correct 74 ms 196724 KB Output is correct
4 Correct 72 ms 196684 KB Output is correct
5 Correct 71 ms 196700 KB Output is correct
6 Correct 71 ms 196756 KB Output is correct
7 Correct 72 ms 196688 KB Output is correct
8 Correct 77 ms 196724 KB Output is correct
9 Correct 87 ms 196744 KB Output is correct
10 Correct 73 ms 196684 KB Output is correct
11 Correct 74 ms 196744 KB Output is correct
12 Correct 72 ms 196720 KB Output is correct
13 Correct 73 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 71 ms 196708 KB Output is correct
16 Correct 85 ms 196708 KB Output is correct
17 Correct 73 ms 196724 KB Output is correct
18 Correct 81 ms 196684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 196772 KB Output is correct
2 Correct 72 ms 196780 KB Output is correct
3 Correct 73 ms 196756 KB Output is correct
4 Correct 77 ms 196780 KB Output is correct
5 Correct 78 ms 196708 KB Output is correct
6 Correct 72 ms 196756 KB Output is correct
7 Correct 74 ms 196684 KB Output is correct
8 Correct 72 ms 196784 KB Output is correct
9 Correct 72 ms 196764 KB Output is correct
10 Correct 87 ms 196680 KB Output is correct
11 Correct 71 ms 196856 KB Output is correct
12 Correct 72 ms 196716 KB Output is correct
13 Correct 71 ms 196768 KB Output is correct
14 Correct 79 ms 196700 KB Output is correct
15 Correct 80 ms 196692 KB Output is correct
16 Correct 71 ms 196708 KB Output is correct
17 Correct 71 ms 196736 KB Output is correct
18 Correct 71 ms 196696 KB Output is correct
19 Correct 75 ms 196704 KB Output is correct
20 Correct 72 ms 196684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 196716 KB Output is correct
2 Correct 73 ms 196768 KB Output is correct
3 Correct 74 ms 196724 KB Output is correct
4 Correct 72 ms 196684 KB Output is correct
5 Correct 71 ms 196700 KB Output is correct
6 Correct 71 ms 196756 KB Output is correct
7 Correct 72 ms 196688 KB Output is correct
8 Correct 77 ms 196724 KB Output is correct
9 Correct 87 ms 196744 KB Output is correct
10 Correct 73 ms 196684 KB Output is correct
11 Correct 74 ms 196744 KB Output is correct
12 Correct 72 ms 196720 KB Output is correct
13 Correct 73 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 71 ms 196708 KB Output is correct
16 Correct 85 ms 196708 KB Output is correct
17 Correct 73 ms 196724 KB Output is correct
18 Correct 81 ms 196684 KB Output is correct
19 Correct 72 ms 196772 KB Output is correct
20 Correct 72 ms 196780 KB Output is correct
21 Correct 73 ms 196756 KB Output is correct
22 Correct 77 ms 196780 KB Output is correct
23 Correct 78 ms 196708 KB Output is correct
24 Correct 72 ms 196756 KB Output is correct
25 Correct 74 ms 196684 KB Output is correct
26 Correct 72 ms 196784 KB Output is correct
27 Correct 72 ms 196764 KB Output is correct
28 Correct 87 ms 196680 KB Output is correct
29 Correct 71 ms 196856 KB Output is correct
30 Correct 72 ms 196716 KB Output is correct
31 Correct 71 ms 196768 KB Output is correct
32 Correct 79 ms 196700 KB Output is correct
33 Correct 80 ms 196692 KB Output is correct
34 Correct 71 ms 196708 KB Output is correct
35 Correct 71 ms 196736 KB Output is correct
36 Correct 71 ms 196696 KB Output is correct
37 Correct 75 ms 196704 KB Output is correct
38 Correct 72 ms 196684 KB Output is correct
39 Correct 74 ms 196692 KB Output is correct
40 Correct 72 ms 196676 KB Output is correct
41 Correct 71 ms 196760 KB Output is correct
42 Correct 80 ms 196792 KB Output is correct
43 Correct 78 ms 196720 KB Output is correct
44 Correct 73 ms 196672 KB Output is correct
45 Correct 75 ms 196772 KB Output is correct
46 Correct 73 ms 196708 KB Output is correct
47 Correct 72 ms 196756 KB Output is correct
48 Correct 84 ms 196796 KB Output is correct
49 Correct 80 ms 196684 KB Output is correct
50 Correct 73 ms 196784 KB Output is correct
51 Correct 82 ms 196736 KB Output is correct
52 Correct 73 ms 196696 KB Output is correct
53 Correct 79 ms 196812 KB Output is correct
54 Correct 82 ms 196784 KB Output is correct
55 Correct 76 ms 196800 KB Output is correct
56 Correct 81 ms 196796 KB Output is correct
57 Correct 78 ms 196804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 196716 KB Output is correct
2 Correct 73 ms 196768 KB Output is correct
3 Correct 74 ms 196724 KB Output is correct
4 Correct 72 ms 196684 KB Output is correct
5 Correct 71 ms 196700 KB Output is correct
6 Correct 71 ms 196756 KB Output is correct
7 Correct 72 ms 196688 KB Output is correct
8 Correct 77 ms 196724 KB Output is correct
9 Correct 87 ms 196744 KB Output is correct
10 Correct 73 ms 196684 KB Output is correct
11 Correct 74 ms 196744 KB Output is correct
12 Correct 72 ms 196720 KB Output is correct
13 Correct 73 ms 196704 KB Output is correct
14 Correct 72 ms 196776 KB Output is correct
15 Correct 71 ms 196708 KB Output is correct
16 Correct 85 ms 196708 KB Output is correct
17 Correct 73 ms 196724 KB Output is correct
18 Correct 81 ms 196684 KB Output is correct
19 Correct 72 ms 196772 KB Output is correct
20 Correct 72 ms 196780 KB Output is correct
21 Correct 73 ms 196756 KB Output is correct
22 Correct 77 ms 196780 KB Output is correct
23 Correct 78 ms 196708 KB Output is correct
24 Correct 72 ms 196756 KB Output is correct
25 Correct 74 ms 196684 KB Output is correct
26 Correct 72 ms 196784 KB Output is correct
27 Correct 72 ms 196764 KB Output is correct
28 Correct 87 ms 196680 KB Output is correct
29 Correct 71 ms 196856 KB Output is correct
30 Correct 72 ms 196716 KB Output is correct
31 Correct 71 ms 196768 KB Output is correct
32 Correct 79 ms 196700 KB Output is correct
33 Correct 80 ms 196692 KB Output is correct
34 Correct 71 ms 196708 KB Output is correct
35 Correct 71 ms 196736 KB Output is correct
36 Correct 71 ms 196696 KB Output is correct
37 Correct 75 ms 196704 KB Output is correct
38 Correct 72 ms 196684 KB Output is correct
39 Correct 74 ms 196692 KB Output is correct
40 Correct 72 ms 196676 KB Output is correct
41 Correct 71 ms 196760 KB Output is correct
42 Correct 80 ms 196792 KB Output is correct
43 Correct 78 ms 196720 KB Output is correct
44 Correct 73 ms 196672 KB Output is correct
45 Correct 75 ms 196772 KB Output is correct
46 Correct 73 ms 196708 KB Output is correct
47 Correct 72 ms 196756 KB Output is correct
48 Correct 84 ms 196796 KB Output is correct
49 Correct 80 ms 196684 KB Output is correct
50 Correct 73 ms 196784 KB Output is correct
51 Correct 82 ms 196736 KB Output is correct
52 Correct 73 ms 196696 KB Output is correct
53 Correct 79 ms 196812 KB Output is correct
54 Correct 82 ms 196784 KB Output is correct
55 Correct 76 ms 196800 KB Output is correct
56 Correct 81 ms 196796 KB Output is correct
57 Correct 78 ms 196804 KB Output is correct
58 Incorrect 75 ms 196816 KB Output isn't correct
59 Halted 0 ms 0 KB -