답안 #37914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37914 2017-12-29T02:45:29 Z Talant K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1000 ms 50464 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 2;

int n,kk;
int dp[102][N];
int a[N];
int t[21][N];

inline int max(int a,int b) {
        return a < b ? b : a;
}

void buildtable() {
        for (int i = 0; i <= log2(n); i ++) {
                for (int j = 1; j <= n; j ++) {
                        if (i == 0) {
                                t[i][j] = a[j];
                                continue;
                        }
                        t[i][j] = max(t[i - 1][j],t[i - 1][j + (1 << (i - 1))]);
                }
        }
}

inline int get (int l,int r) {
        int cur = log2(r - l + 1);
        return max(t[cur][l],t[cur][r - (1 << cur) + 1]);
}

void compute (int k,int l,int r,int L,int R) {
        if (l > r)
                return;

        int m = (r + l) / 2;
        int opt = -1;
        int &d = dp[k][m];

        for (int i = L; i <= min(m,R); i ++) {
                int now = dp[k - 1][i - 1] + get(i,m);
                if (now < d)
                        d = now,opt = i;
        }
        compute (k,l,m - 1,L,opt);
        compute (k,m + 1,r,opt,R);
}
main () {
        scanf ("%d%d", &n,&kk);

        for (int i = 1; i <= n; i ++)
                scanf ("%d", &a[i]);

        memset(dp,0x3f3f3f3f,sizeof(dp));

        buildtable();

        for (int i = 1; i <= n; i ++)
                dp[1][i] = get(1,i);

        for (int i = 2; i <= kk; i ++)
                compute (i,i,n,i,n);

        cout << dp[kk][n] << endl;
}

Compilation message

blocks.cpp:58:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
blocks.cpp: In function 'int main()':
blocks.cpp:59:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d%d", &n,&kk);
                               ^
blocks.cpp:62:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", &a[i]);
                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 50464 KB Output is correct
2 Correct 0 ms 50464 KB Output is correct
3 Correct 3 ms 50464 KB Output is correct
4 Correct 3 ms 50464 KB Output is correct
5 Correct 0 ms 50464 KB Output is correct
6 Correct 0 ms 50464 KB Output is correct
7 Correct 3 ms 50464 KB Output is correct
8 Correct 0 ms 50464 KB Output is correct
9 Correct 0 ms 50464 KB Output is correct
10 Correct 3 ms 50464 KB Output is correct
11 Incorrect 0 ms 50464 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 50464 KB Output is correct
2 Correct 6 ms 50464 KB Output is correct
3 Correct 6 ms 50464 KB Output is correct
4 Correct 9 ms 50464 KB Output is correct
5 Correct 0 ms 50464 KB Output is correct
6 Correct 0 ms 50464 KB Output is correct
7 Correct 3 ms 50464 KB Output is correct
8 Correct 6 ms 50464 KB Output is correct
9 Correct 3 ms 50464 KB Output is correct
10 Correct 3 ms 50464 KB Output is correct
11 Incorrect 0 ms 50464 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 50464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 50464 KB Output is correct
2 Correct 6 ms 50464 KB Output is correct
3 Correct 139 ms 50464 KB Output is correct
4 Execution timed out 1000 ms 50464 KB Execution timed out
5 Halted 0 ms 0 KB -