Submission #37915

# Submission time Handle Problem Language Result Execution time Memory
37915 2017-12-29T02:48:09 Z Talant K blocks (IZhO14_blocks) C++14
0 / 100
93 ms 50468 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]);

        sort (a + 1,a + n + 1);

        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]);
                                    ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 50468 KB Output is correct
2 Correct 6 ms 50468 KB Output is correct
3 Correct 0 ms 50468 KB Output is correct
4 Correct 3 ms 50468 KB Output is correct
5 Correct 3 ms 50468 KB Output is correct
6 Correct 3 ms 50468 KB Output is correct
7 Incorrect 6 ms 50468 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 50468 KB Output is correct
2 Correct 6 ms 50468 KB Output is correct
3 Correct 0 ms 50468 KB Output is correct
4 Correct 3 ms 50468 KB Output is correct
5 Correct 0 ms 50468 KB Output is correct
6 Correct 0 ms 50468 KB Output is correct
7 Incorrect 3 ms 50468 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 50468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 50468 KB Output isn't correct
2 Halted 0 ms 0 KB -