Submission #1040379

# Submission time Handle Problem Language Result Execution time Memory
1040379 2024-08-01T02:45:40 Z vjudge1 K blocks (IZhO14_blocks) C++17
53 / 100
1000 ms 83288 KB
#include <bits/stdc++.h>
#define Y8o "K blocks"
#define maxn (int) 1e5 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
 
//#define f first
//#define s second
 
using namespace std;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".in", "r"))
    {
        freopen(Y8o".in", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
 
 
int n, k;
int a[maxn];
ll s[maxn], dp[105][maxn];
 
void solve()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> a[i], s[i] = s[i - 1] + a[i];
 
    memset(dp, 0x3f, sizeof dp);
 
    int mx2 = 0;
    for(int i = 1; i <= n; i ++) mx2 = max(mx2, a[i]), dp[1][i] = mx2;
 
    for(int i = 2; i <= k; i ++) {
        for(int j = 1; j <= n; j ++) {
            int mx = 0;
            for(int t = j; t >= 1; t --) {
                mx = max(mx, a[t]);
                dp[i][j] = min(dp[i][j], dp[i - 1][t - 1] + mx);
            }
        }
    }
 
    cout << dp[k][n];
}
 
 
int main()
{
    iof();
 
    int nTest = 1;
//    cin >> nTest;
 
    while(nTest --) {
        solve();
    }
 
    ctime();
    return 0;
}

Compilation message

blocks.cpp: In function 'void iof()':
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(Y8o".in", "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(Y8o".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 34 ms 82504 KB Output is correct
2 Correct 34 ms 82516 KB Output is correct
3 Correct 35 ms 82516 KB Output is correct
4 Correct 33 ms 82512 KB Output is correct
5 Correct 33 ms 82512 KB Output is correct
6 Correct 37 ms 82516 KB Output is correct
7 Correct 32 ms 82520 KB Output is correct
8 Correct 33 ms 82520 KB Output is correct
9 Correct 30 ms 82496 KB Output is correct
10 Correct 35 ms 82520 KB Output is correct
11 Correct 30 ms 82520 KB Output is correct
12 Correct 32 ms 82516 KB Output is correct
13 Correct 30 ms 82516 KB Output is correct
14 Correct 31 ms 82516 KB Output is correct
15 Correct 31 ms 82520 KB Output is correct
16 Correct 31 ms 82476 KB Output is correct
17 Correct 31 ms 82516 KB Output is correct
18 Correct 31 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 82512 KB Output is correct
2 Correct 39 ms 82520 KB Output is correct
3 Correct 30 ms 82532 KB Output is correct
4 Correct 31 ms 82524 KB Output is correct
5 Correct 31 ms 82516 KB Output is correct
6 Correct 31 ms 82524 KB Output is correct
7 Correct 32 ms 82524 KB Output is correct
8 Correct 32 ms 82536 KB Output is correct
9 Correct 34 ms 82532 KB Output is correct
10 Correct 34 ms 82532 KB Output is correct
11 Correct 36 ms 82668 KB Output is correct
12 Correct 38 ms 82528 KB Output is correct
13 Correct 32 ms 82536 KB Output is correct
14 Correct 32 ms 82536 KB Output is correct
15 Correct 34 ms 82580 KB Output is correct
16 Correct 35 ms 82528 KB Output is correct
17 Correct 34 ms 82608 KB Output is correct
18 Correct 35 ms 82524 KB Output is correct
19 Correct 34 ms 82620 KB Output is correct
20 Correct 32 ms 82576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 82504 KB Output is correct
2 Correct 34 ms 82516 KB Output is correct
3 Correct 35 ms 82516 KB Output is correct
4 Correct 33 ms 82512 KB Output is correct
5 Correct 33 ms 82512 KB Output is correct
6 Correct 37 ms 82516 KB Output is correct
7 Correct 32 ms 82520 KB Output is correct
8 Correct 33 ms 82520 KB Output is correct
9 Correct 30 ms 82496 KB Output is correct
10 Correct 35 ms 82520 KB Output is correct
11 Correct 30 ms 82520 KB Output is correct
12 Correct 32 ms 82516 KB Output is correct
13 Correct 30 ms 82516 KB Output is correct
14 Correct 31 ms 82516 KB Output is correct
15 Correct 31 ms 82520 KB Output is correct
16 Correct 31 ms 82476 KB Output is correct
17 Correct 31 ms 82516 KB Output is correct
18 Correct 31 ms 82520 KB Output is correct
19 Correct 38 ms 82512 KB Output is correct
20 Correct 39 ms 82520 KB Output is correct
21 Correct 30 ms 82532 KB Output is correct
22 Correct 31 ms 82524 KB Output is correct
23 Correct 31 ms 82516 KB Output is correct
24 Correct 31 ms 82524 KB Output is correct
25 Correct 32 ms 82524 KB Output is correct
26 Correct 32 ms 82536 KB Output is correct
27 Correct 34 ms 82532 KB Output is correct
28 Correct 34 ms 82532 KB Output is correct
29 Correct 36 ms 82668 KB Output is correct
30 Correct 38 ms 82528 KB Output is correct
31 Correct 32 ms 82536 KB Output is correct
32 Correct 32 ms 82536 KB Output is correct
33 Correct 34 ms 82580 KB Output is correct
34 Correct 35 ms 82528 KB Output is correct
35 Correct 34 ms 82608 KB Output is correct
36 Correct 35 ms 82524 KB Output is correct
37 Correct 34 ms 82620 KB Output is correct
38 Correct 32 ms 82576 KB Output is correct
39 Correct 34 ms 82524 KB Output is correct
40 Correct 37 ms 82620 KB Output is correct
41 Correct 34 ms 82512 KB Output is correct
42 Correct 33 ms 82544 KB Output is correct
43 Correct 33 ms 82516 KB Output is correct
44 Correct 34 ms 82520 KB Output is correct
45 Correct 32 ms 82512 KB Output is correct
46 Correct 33 ms 82512 KB Output is correct
47 Correct 32 ms 82512 KB Output is correct
48 Correct 32 ms 82528 KB Output is correct
49 Correct 33 ms 82520 KB Output is correct
50 Correct 37 ms 82592 KB Output is correct
51 Correct 33 ms 82516 KB Output is correct
52 Correct 36 ms 82524 KB Output is correct
53 Correct 36 ms 82516 KB Output is correct
54 Correct 33 ms 82608 KB Output is correct
55 Correct 32 ms 82516 KB Output is correct
56 Correct 34 ms 82512 KB Output is correct
57 Correct 33 ms 82516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 82504 KB Output is correct
2 Correct 34 ms 82516 KB Output is correct
3 Correct 35 ms 82516 KB Output is correct
4 Correct 33 ms 82512 KB Output is correct
5 Correct 33 ms 82512 KB Output is correct
6 Correct 37 ms 82516 KB Output is correct
7 Correct 32 ms 82520 KB Output is correct
8 Correct 33 ms 82520 KB Output is correct
9 Correct 30 ms 82496 KB Output is correct
10 Correct 35 ms 82520 KB Output is correct
11 Correct 30 ms 82520 KB Output is correct
12 Correct 32 ms 82516 KB Output is correct
13 Correct 30 ms 82516 KB Output is correct
14 Correct 31 ms 82516 KB Output is correct
15 Correct 31 ms 82520 KB Output is correct
16 Correct 31 ms 82476 KB Output is correct
17 Correct 31 ms 82516 KB Output is correct
18 Correct 31 ms 82520 KB Output is correct
19 Correct 38 ms 82512 KB Output is correct
20 Correct 39 ms 82520 KB Output is correct
21 Correct 30 ms 82532 KB Output is correct
22 Correct 31 ms 82524 KB Output is correct
23 Correct 31 ms 82516 KB Output is correct
24 Correct 31 ms 82524 KB Output is correct
25 Correct 32 ms 82524 KB Output is correct
26 Correct 32 ms 82536 KB Output is correct
27 Correct 34 ms 82532 KB Output is correct
28 Correct 34 ms 82532 KB Output is correct
29 Correct 36 ms 82668 KB Output is correct
30 Correct 38 ms 82528 KB Output is correct
31 Correct 32 ms 82536 KB Output is correct
32 Correct 32 ms 82536 KB Output is correct
33 Correct 34 ms 82580 KB Output is correct
34 Correct 35 ms 82528 KB Output is correct
35 Correct 34 ms 82608 KB Output is correct
36 Correct 35 ms 82524 KB Output is correct
37 Correct 34 ms 82620 KB Output is correct
38 Correct 32 ms 82576 KB Output is correct
39 Correct 34 ms 82524 KB Output is correct
40 Correct 37 ms 82620 KB Output is correct
41 Correct 34 ms 82512 KB Output is correct
42 Correct 33 ms 82544 KB Output is correct
43 Correct 33 ms 82516 KB Output is correct
44 Correct 34 ms 82520 KB Output is correct
45 Correct 32 ms 82512 KB Output is correct
46 Correct 33 ms 82512 KB Output is correct
47 Correct 32 ms 82512 KB Output is correct
48 Correct 32 ms 82528 KB Output is correct
49 Correct 33 ms 82520 KB Output is correct
50 Correct 37 ms 82592 KB Output is correct
51 Correct 33 ms 82516 KB Output is correct
52 Correct 36 ms 82524 KB Output is correct
53 Correct 36 ms 82516 KB Output is correct
54 Correct 33 ms 82608 KB Output is correct
55 Correct 32 ms 82516 KB Output is correct
56 Correct 34 ms 82512 KB Output is correct
57 Correct 33 ms 82516 KB Output is correct
58 Correct 865 ms 82680 KB Output is correct
59 Correct 36 ms 83280 KB Output is correct
60 Execution timed out 1046 ms 83288 KB Time limit exceeded
61 Halted 0 ms 0 KB -