답안 #1016944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016944 2024-07-08T15:58:03 Z ByeWorld K개의 묶음 (IZhO14_blocks) C++14
53 / 100
1000 ms 14940 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
const int MAXN = 1e5+10;
const int MAXK = 110;
const ll INF = 1e18+10;
const int LOG = 19;
const int MOD = 1e9+7;
const int SQRT = 450;
const vector<int> NOL = {};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
void chmn(int &a, int b){ a = min(a, b); }

int n, k;
ll dp[MAXN][MAXK];
int sp[MAXN][LOG+5], a[MAXN];

int GET(int x, int y){
    int lg = log2(y-x+1);
    return max(sp[x][lg], sp[y-(1<<lg)+1][lg]);
}

void bd(int IDX, int l, int r, int optl, int optr){
    if(l>r) return;
    int mid = md; // dp[mid][IDX]
    int opt = -1;
    for(int i=optl; i<=min(optr, mid-1); i++){
        ll te = dp[i][IDX-1] + GET(i+1, mid);
        if(dp[mid][IDX] > te){
           dp[mid][IDX] = te; opt = i;
        }
    }

    bd(IDX, l, mid-1, optl, opt); bd(IDX, mid+1, r, opt, optr);
}
signed main(){
    // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++){ cin >> a[i]; sp[i][0] = a[i]; }
    for(int j=1; j<LOG; j++){
        for(int i=1; i<=n-(1<<j)+1; i++){
            sp[i][j] = max(sp[i][j-1], sp[i+(1<<(j-1))][j-1]);
        }
    }
    for(int p=0; p<=k; p++)
        for(int i=0; i<=n; i++) dp[i][p] = INF;
    dp[0][0] = 0;
    for(int xx=1; xx<=k; xx++) bd(xx, xx, n, xx-1, n);

    for(int p=1; p<=k; p++){
        for(int i=p; i<=n; i++){
            dp[i][p] = INF;
            for(int j=p-1; j<=i-1; j++){
                chmn(dp[i][p], dp[j][p-1] + GET(j+1, i));
            }
        }
    }
    cout << dp[n][k] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4600 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4544 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4544 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4540 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4600 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4544 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4544 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4540 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 3 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4540 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 3 ms 4548 KB Output is correct
52 Correct 2 ms 4552 KB Output is correct
53 Correct 3 ms 4548 KB Output is correct
54 Correct 3 ms 4444 KB Output is correct
55 Correct 3 ms 4444 KB Output is correct
56 Correct 3 ms 4444 KB Output is correct
57 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4600 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4544 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4544 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4540 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 3 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4540 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 3 ms 4548 KB Output is correct
52 Correct 2 ms 4552 KB Output is correct
53 Correct 3 ms 4548 KB Output is correct
54 Correct 3 ms 4444 KB Output is correct
55 Correct 3 ms 4444 KB Output is correct
56 Correct 3 ms 4444 KB Output is correct
57 Correct 3 ms 4444 KB Output is correct
58 Execution timed out 1047 ms 14940 KB Time limit exceeded
59 Halted 0 ms 0 KB -