제출 #37549

#제출 시각아이디문제언어결과실행 시간메모리
37549TalantSplit the sequence (APIO14_sequence)C++11
0 / 100
49 ms82880 KiB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = (int)1e5 + 7;

ll dp[N][2];
ll p[N];
int pr[N][201];
int n;

inline ll calc (int r,int l) {
        return p[l] * (p[r] - p[l]);
}
inline int min(int a, int b)
{
        return a < b ? a : b;
}
void compute (int k,int l,int r,int L,int R) {

        if (l > r) return;

        int m = (l + r) >> 1;

        dp[m][k & 1] = 0;

        int opt = L;

        for (int i = L; i <= min(m - 1,R); i ++) {

                ll now = dp[i][k % 2] + calc(m,i);

                if (now > dp[m][k & 1]) {
                        dp[m][k & 1] = now;
                        opt = i;
                }
        }
        pr[m][k] = opt;

        compute (k, l,m - 1, L, pr[m][k]);
        compute (k, m + 1, r, pr[m][k], R);
}

int kk;
main () {
        scanf ("%d%d", &n,&kk);

        for (int i = 1; i <= n; i ++) {
                scanf ("%lld", &p[i]);
                p[i] += p[i - 1];
        }

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

        printf("%lld\n", dp[n][kk & 1]);


        while (kk > 0) {
               printf("%d ", pr[n][kk]);
                n = pr[n][kk];
                kk --;
        }
}
/**
7 3
4 1 3 4 0 2 3
**/

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:47:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:48:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d%d", &n,&kk);
                               ^
sequence.cpp:51:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%lld", &p[i]);
                                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...