Submission #927489

#TimeUsernameProblemLanguageResultExecution timeMemory
927489AlphaMale06Split the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

using ld = long double;

#define int long long
#define pb push_back
#define F first
#define S second

int dp[2][205][100010];
deque<pair<line, int>> cht;

struct line{
    int slope, c;
    int eval(int x){
        return slope*x+c;
    }
    ld interx(line & a){
        return (ld)(a.c-c)/(ld)(slope-a.slope);
    }
};

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    int pref[n+1];
    pref[0]=0;
    for(int i=0; i< n; i++){
        cin >> a[i];
        pref[i+1]=pref[i]+a[i];
    }
    for(int j=1; j<=k; j++){
        cht.pb({{-pref[j-1], dp[0][j-1][j]}, j});
        for(int i=j+1; i<=n; i++){
            int x = pref[n]-pref[i-1];
            while(cht.size()>=2){
                pair<line, int> l = cht.back();
                cht.pop_back();
                if(l.F.eval(x)>cht.back().F.eval(x)){
                    cht.push_back(l);
                    break;
                }
            }
            dp[0][j][i]=cht.back().F.eval(x)+pref[i-1]*(pref[n]-pref[i-1]);
            dp[1][j][i]=cht.back().S;
            pair<line, int> np = {{-pref[i-1], dp[0][j-1][i]}, i};
            while(cht.size()>=2){
                pair<line, int> f = cht.front();
                cht.pop_front();
                if(f.F.slope==np.F.slope){
                    if(f.F.c<=np.F.c)continue;
                    else break;
                }
                ld inter1 = f.F.interx(cht.front().F);
                ld inter2 = np.F.interx(cht.front().F);
                if(inter2<inter1){
                    cht.push_front(f);
                    break;
                }
            }
            cht.push_front(np);
        }
        while(cht.size())cht.pop_back();
    }
    int ans=0;
    int ind=0;
    for(int i=1; i<=n; i++){
        if(dp[0][k][i]>=ans){
            ans=dp[0][k][i];
            ind=i;
        }
    }
    cout << ans << '\n';
    vector<int> con;
    con.pb(ind);
    for(int i=k; i>1; i--){
        con.pb(dp[1][i][ind]);
        ind=dp[1][i][ind];
    }
    sort(con.begin(), con.end());
    for(int i=0; i<k; i++){
        cout << con[i]-1 << " ";
    }
    cout << '\n';

}

Compilation message (stderr)

sequence.cpp:13:12: error: 'line' was not declared in this scope
   13 | deque<pair<line, int>> cht;
      |            ^~~~
sequence.cpp:7:18: error: template argument 1 is invalid
    7 | #define int long long
      |                  ^~~~
sequence.cpp:13:18: note: in expansion of macro 'int'
   13 | deque<pair<line, int>> cht;
      |                  ^~~
sequence.cpp:13:21: error: template argument 1 is invalid
   13 | deque<pair<line, int>> cht;
      |                     ^~
sequence.cpp:13:21: error: template argument 2 is invalid
sequence.cpp: In function 'int main()':
sequence.cpp:8:12: error: request for member 'push_back' in 'cht', which is of non-class type 'int'
    8 | #define pb push_back
      |            ^~~~~~~~~
sequence.cpp:39:13: note: in expansion of macro 'pb'
   39 |         cht.pb({{-pref[j-1], dp[0][j-1][j]}, j});
      |             ^~
sequence.cpp:42:23: error: request for member 'size' in 'cht', which is of non-class type 'int'
   42 |             while(cht.size()>=2){
      |                       ^~~~
sequence.cpp:43:41: error: request for member 'back' in 'cht', which is of non-class type 'int'
   43 |                 pair<line, int> l = cht.back();
      |                                         ^~~~
sequence.cpp:44:21: error: request for member 'pop_back' in 'cht', which is of non-class type 'int'
   44 |                 cht.pop_back();
      |                     ^~~~~~~~
sequence.cpp:45:36: error: request for member 'back' in 'cht', which is of non-class type 'int'
   45 |                 if(l.F.eval(x)>cht.back().F.eval(x)){
      |                                    ^~~~
sequence.cpp:46:25: error: request for member 'push_back' in 'cht', which is of non-class type 'int'
   46 |                     cht.push_back(l);
      |                         ^~~~~~~~~
sequence.cpp:50:29: error: request for member 'back' in 'cht', which is of non-class type 'int'
   50 |             dp[0][j][i]=cht.back().F.eval(x)+pref[i-1]*(pref[n]-pref[i-1]);
      |                             ^~~~
sequence.cpp:51:29: error: request for member 'back' in 'cht', which is of non-class type 'int'
   51 |             dp[1][j][i]=cht.back().S;
      |                             ^~~~
sequence.cpp:53:23: error: request for member 'size' in 'cht', which is of non-class type 'int'
   53 |             while(cht.size()>=2){
      |                       ^~~~
sequence.cpp:54:41: error: request for member 'front' in 'cht', which is of non-class type 'int'
   54 |                 pair<line, int> f = cht.front();
      |                                         ^~~~~
sequence.cpp:55:21: error: request for member 'pop_front' in 'cht', which is of non-class type 'int'
   55 |                 cht.pop_front();
      |                     ^~~~~~~~~
sequence.cpp:60:44: error: request for member 'front' in 'cht', which is of non-class type 'int'
   60 |                 ld inter1 = f.F.interx(cht.front().F);
      |                                            ^~~~~
sequence.cpp:61:45: error: request for member 'front' in 'cht', which is of non-class type 'int'
   61 |                 ld inter2 = np.F.interx(cht.front().F);
      |                                             ^~~~~
sequence.cpp:63:25: error: request for member 'push_front' in 'cht', which is of non-class type 'int'
   63 |                     cht.push_front(f);
      |                         ^~~~~~~~~~
sequence.cpp:67:17: error: request for member 'push_front' in 'cht', which is of non-class type 'int'
   67 |             cht.push_front(np);
      |                 ^~~~~~~~~~
sequence.cpp:69:19: error: request for member 'size' in 'cht', which is of non-class type 'int'
   69 |         while(cht.size())cht.pop_back();
      |                   ^~~~
sequence.cpp:69:30: error: request for member 'pop_back' in 'cht', which is of non-class type 'int'
   69 |         while(cht.size())cht.pop_back();
      |                              ^~~~~~~~