Submission #1016939

# Submission time Handle Problem Language Result Execution time Memory
1016939 2024-07-08T15:56:00 Z ByeWorld K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 4540 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=1; i<=n; i++){
    //         for(int j=0; j<=i-1; j++){
    //             chmn(dp[i][p], dp[j][p-1] + GET(j+1, i));
    //         }
    //     }
    // }
    cout << dp[n][k] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 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 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Incorrect 1 ms 4444 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4540 KB Output is correct
5 Correct 1 ms 4440 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 Incorrect 1 ms 4440 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 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 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Incorrect 1 ms 4444 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 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 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Incorrect 1 ms 4444 KB Output isn't correct
12 Halted 0 ms 0 KB -