Submission #34038

#TimeUsernameProblemLanguageResultExecution timeMemory
34038wan2000Split the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

template<typename T> read(T &x){
    x = 0; char ch; while(!isdigit(ch=getchar()));
    do{ x = 10*x+ch-'0'; } while(isdigit(ch=getchar()));
}

typedef long long ll;

const int N = 1e5+111;
const int K = 222;

int n, k, Tr[K][N];
ll A[N], S[N], F[K][N], res;

bool maxi(ll &x, ll y){
    if(x<y) x = y;
    else return 0;
    return 1;
}

void BackTrack(int x, int d){
    if(d==0) return;
    cout<<x<<' ';
    BackTrack(Tr[d][x],d-1);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    read(n); read(k);
    for(int i = 1; i <= n; i++){
        read(A[i]);
        S[i] = S[i-1]+A[i];
    }
    for(int ii = 1; ii <= k; ii++){
        for(int i = n; i >= 1; i--){
            F[ii][i] = 0;
            for(int j = i+1; j <= n; j++){
                if(maxi(F[ii][i],F[ii-1][j]+S[i]*(S[j]-S[i]))){
                    Tr[ii][i] = j;
                }
            }
        }
    }
    int s;
    for(int i = 1; i <= n; i++){
        if(maxi(res,F[k][i])){
            s = i;
        }
    }
    cout<<res<<'\n';
    BackTrack(s,k);
    return 0;
}

Compilation message (stderr)

sequence.cpp:5:31: error: ISO C++ forbids declaration of 'read' with no type [-fpermissive]
 template<typename T> read(T &x){
                               ^
sequence.cpp: In function 'int read(T&)':
sequence.cpp:8:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^