답안 #37913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37913 2017-12-29T02:43:46 Z Just_Solve_The_Problem K개의 묶음 (IZhO14_blocks) C++11
0 / 100
16 ms 12172 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = (int)1e5 + 7;
const ll linf = (ll)1e15 + 7;

ll dp[2][N];
int ar[N];
int numlog[N];
int table[20][N];
int n;

void buildtable () {
    for (int i = 2; i <= n; i++) {
        numlog[i] = numlog[i / 2] + 1;
    }
    for (int i = 0; i <= numlog[n]; i++) {
        int curlen = 1 << i;
        for (int j = 1; j <= n; j++) {
            if (i == 0) {
                table[i][j] = ar[j];
                continue;
            }
            table[i][j] = max(table[i - 1][j], table[i - 1][j + curlen / 2]);
        }
    }
}

int get (int l, int r) {
    int curlog = numlog[r - l + 1];
    return max(table[curlog][l], table[curlog][r - (1 << curlog) + 1]);
}

void div (int k, int l, int r, int optl, int optr) {
    if (l > r) return ;
    int mid = (l + r) >> 1;
    int opt = optl;
    for (int i = optl; i <= min(mid, optr); i++) {
        ll cur = dp[k & 1 ^ 1][i - 1] + get(i, mid);
        if (cur < dp[k & 1][mid]) {
            dp[k & 1][mid] = cur;
            opt = i;
        }
    }
    div(k, l, mid - 1, optl, opt);
    div(k, mid + 1, r, opt, optr);
}

main() {
    int k;
    scanf ("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", ar + i);
    }
    buildtable();
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= 1; j++) {
            dp[j][i] = linf;
        }
    }
    dp[0][0] = 0;
//    cout << get(1, n) << endl;
    for (int i = 1; i <= k; i++) {
        div(i, 1, n, 1, n);
    }
//    for (int i = 1; i <= n; i++) {
//        cout << dp[k & 1][i] << ' ';
//    }
    cout << dp[k & 1][n];
}

Compilation message

blocks.cpp: In function 'void div(int, int, int, int, int)':
blocks.cpp:42:23: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         ll cur = dp[k & 1 ^ 1][i - 1] + get(i, mid);
                       ^
blocks.cpp: At global scope:
blocks.cpp:52:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:54:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &n, &k);
                            ^
blocks.cpp:56:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", ar + i);
                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12172 KB Output is correct
2 Correct 0 ms 12172 KB Output is correct
3 Correct 0 ms 12172 KB Output is correct
4 Correct 0 ms 12172 KB Output is correct
5 Correct 0 ms 12172 KB Output is correct
6 Correct 0 ms 12172 KB Output is correct
7 Correct 0 ms 12172 KB Output is correct
8 Correct 0 ms 12172 KB Output is correct
9 Incorrect 0 ms 12172 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 12172 KB Output is correct
2 Correct 0 ms 12172 KB Output is correct
3 Correct 0 ms 12172 KB Output is correct
4 Correct 0 ms 12172 KB Output is correct
5 Correct 0 ms 12172 KB Output is correct
6 Correct 0 ms 12172 KB Output is correct
7 Correct 0 ms 12172 KB Output is correct
8 Correct 0 ms 12172 KB Output is correct
9 Incorrect 0 ms 12172 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 12172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 12172 KB Output isn't correct
2 Halted 0 ms 0 KB -