제출 #37548

#제출 시각아이디문제언어결과실행 시간메모리
37548Talant수열 (APIO14_sequence)C++11
71 / 100
2000 ms82880 KiB
#include <bits/stdc++.h>

#define ll long long

using namespace std;


const ll inf = (ll)1e9 + 7;
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 & 1 ^ 1] + 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);
}

main () {
        int kk;
        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: In function 'void compute(int, int, int, int, int)':
sequence.cpp:33:34: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
                 ll now = dp[i][k & 1 ^ 1] + calc(m,i);
                                  ^
sequence.cpp: At global scope:
sequence.cpp:45:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:47: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:50: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...