Submission #21780

# Submission time Handle Problem Language Result Execution time Memory
21780 2017-04-22T00:04:09 Z jjwdi0 K blocks (IZhO14_blocks) C++11
0 / 100
19 ms 90304 KB
#include <bits/stdc++.h>
#define log_N 18
using namespace std;

int N, K;
int A[100005];
int D[103][100005], C[103][100005];
int len[100005];
int par[100005][log_N];

void init() {
    int k = 0;
    for(int i=0; i<=N; i++) {
        if(i == (1 << k)) k++;
        len[i] = k;
    }
}

int RMQ(int s, int e) { return max(par[e][len[e-s]], par[s+(1<<len[e-s])-1][len[e-s]]); }

void D_C(int k, int s, int e, int l, int r) {
    if(s > e) return;
    int mid = s + e >> 1;
    D[k][mid] = 2e9;
    for(int i=l; i<=r && i<mid; i++) {
        int v = D[k-1][i] + RMQ(i + 1, mid);
        if(D[k][mid] > v) D[k][mid] = v, C[k][mid] = i;
    }
    D_C(k, s, mid - 1, l, C[k][mid]);
    D_C(k, mid + 1, e, C[k][mid], r);
}

int main() {
    scanf("%d %d", &N, &K);
    for(int i=1; i<=N; i++) scanf("%d", A+i);
    for(int i=1; i<=N; i++) par[i][0] = A[i];
    for(int i=1; i<log_N; i++) for(int j=1; j<=N; j++) par[j][i] = max(par[j][i-1], par[par[j][i-1]][i-1]);
    for(int i=1; i<=N; i++) D[1][i] = par[i][log_N-1];
    for(int i=2; i<=K; i++) D_C(i, 1, N, 1, N);
    printf("%d\n", D[K][N]);
}

Compilation message

blocks.cpp: In function 'void D_C(int, int, int, int, int)':
blocks.cpp:23:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = s + e >> 1;
                 ^
blocks.cpp: In function 'int main()':
blocks.cpp:34:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
                           ^
blocks.cpp:35:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d", A+i);
                                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 90304 KB Output is correct
2 Correct 0 ms 90304 KB Output is correct
3 Correct 0 ms 90304 KB Output is correct
4 Incorrect 0 ms 90304 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 90304 KB Output is correct
2 Correct 0 ms 90304 KB Output is correct
3 Correct 0 ms 90304 KB Output is correct
4 Incorrect 0 ms 90304 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 90304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 90304 KB Output isn't correct
2 Halted 0 ms 0 KB -