답안 #37910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37910 2017-12-29T02:40:14 Z Talant K개의 묶음 (IZhO14_blocks) C++14
0 / 100
96 ms 20776 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 long long inf = (long long)1e18 + 7;
const long long N = (long long)1e5 + 2;

long long n,kk;
long long dp[2][N];
long long a[N];
long long t[21][N];

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

void buildtable() {
        for (long long i = 0; i <= log2(n); i ++) {
                for (long long 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 long long get (long long l,long long r) {
        long long cur = log2(r - l + 1);
        return max(t[cur][l],t[cur][r - (1 << cur) + 1]);
}

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

        long long m = (r + l) / 2;
        long long opt = L;
        long long &d = dp[k][m];

        for (long long i = L; i <= min(m,R); i ++) {
                long long 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 ("%lld%lld", &n,&kk);

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

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

        buildtable();

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

        for (long long i = 2; i <= kk; i ++)
                compute (i & 1,i,n,i,n);

        cout << dp[kk & 1][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:64:48: warning: overflow in implicit constant conversion [-Woverflow]
         memset(dp,0x3f3f3f3f3f3f3f3f,sizeof(dp));
                                                ^
blocks.cpp:59:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%lld%lld", &n,&kk);
                                   ^
blocks.cpp:62:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%lld", &a[i]);
                                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 20776 KB Output is correct
2 Correct 0 ms 20776 KB Output is correct
3 Correct 0 ms 20776 KB Output is correct
4 Correct 0 ms 20776 KB Output is correct
5 Correct 0 ms 20776 KB Output is correct
6 Correct 0 ms 20776 KB Output is correct
7 Correct 0 ms 20776 KB Output is correct
8 Correct 0 ms 20776 KB Output is correct
9 Incorrect 0 ms 20776 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 20776 KB Output is correct
2 Correct 0 ms 20776 KB Output is correct
3 Correct 0 ms 20776 KB Output is correct
4 Correct 0 ms 20776 KB Output is correct
5 Correct 0 ms 20776 KB Output is correct
6 Correct 0 ms 20776 KB Output is correct
7 Correct 0 ms 20776 KB Output is correct
8 Correct 0 ms 20776 KB Output is correct
9 Incorrect 0 ms 20776 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 20776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 20776 KB Output isn't correct
2 Halted 0 ms 0 KB -