제출 #37507

#제출 시각아이디문제언어결과실행 시간메모리
37507Talant수열 (APIO14_sequence)C++11
60 / 100
179 ms25692 KiB
#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 ll inf = (ll)1e9 + 7;
const int N = (int)1e4 + 2;

int n,k,id;
int pr[N][201],a[N];
int cnt,o;

ll p[N];
ll dp[N][201];
ll mx;

ll calc (int r,int l) {
        return (p[r] - p[l]) * 1ll * (p[n] - p[r]);
}
void compute (int k,int l,int r,int L,int R) {
        if (l > r)
                return;

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

        for (int i = L; i <= min(m,R); i ++) {
                ll now = dp[i - 1][(k - 1)] + calc(m,i - 1);
                if (now > dp[m][k])
                        dp[m][k ] = now,opt = i;
        }
        pr[m][k] = opt;

        compute (k,l,m - 1,L,opt);
        compute (k,m + 1,r,opt,R);
}
int main () {
        scanf ("%d%d", &n,&k);

        o = k;

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

        for (int i = 1; i <= n; i ++) {
                dp[i][1] = calc(i,0);
                pr[i][1] = 1;
        }

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

        for (int i = 1; i <= n; i ++) {
                if (mx < dp[i][k ])
                        mx = max(mx,dp[i][k ]),id = i;
        }

        printf("%lld\n", mx);

        deque<int> dq;

        while (id > 0 && k > 0) {
                if (cnt == o)
                        break;
                dq.push_front(id);
                id = pr[id][k] - 1;
                k --;
                cnt ++;
        }
        for (int i = 0; i < (int)dq.size(); i ++)
                printf("%d ", dq[i]);
}
/**
7 3
4 1 3 4 0 2 3
**/

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

sequence.cpp: In function 'int main()':
sequence.cpp:50:37: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
                 scanf ("%lld", &a[i]);
                                     ^
sequence.cpp:45:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d%d", &n,&k);
                              ^
sequence.cpp:50:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%lld", &a[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...