Submission #562996

#TimeUsernameProblemLanguageResultExecution timeMemory
562996penguin133Split the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; pair<long long, int> dp[201[100001]; long long P[100005]; int A[100005]; int n,k; void dnc(int l, int r, int optl, int optr, int i){ if(l > r)return; int mid = (l + r)/2,pos = optl; long long maxx = -1e12; for(int j=optl;j<=min(optr, mid-1);j++){ long long ans = dp[i-1][j].first + (P[mid] - P[j]) * (P[n] - P[mid]); if(ans > maxx)maxx = ans, pos = j; } dp[i][mid] = make_pair(maxx,pos); dnc(l,mid-1,optl,pos,i); dnc(mid+1,r,pos,optr,i); } main(){ ios::sync_with_stdio(0);cin.tie(0); cin >> n >> k; for(int i=1;i<=n;i++)cin >> A[i], P[i] = P[i-1] + A[i]; for(int i=1;i<=n;i++)dp[1][i].first = (P[n] - P[i])*P[i]; for(int i=2;i<=k;i++)dnc(1,n,1,n,i); long long maxi = -1e12, in=1; for(int i=1;i<=n;i++)if(dp[k][i].first > maxi)maxi = dp[k][i].first, in = i; cout << maxi << '\n'; cout << in << " "; int p = dp[k][in].second; while(p)cout << p << " ", k--, p = dp[k][p].second; }

Compilation message (stderr)

sequence.cpp:3:28: error: invalid types 'int[int]' for array subscript
    3 | pair<long long, int> dp[201[100001];
      |                            ^
sequence.cpp:3:36: error: expected ']' before ';' token
    3 | pair<long long, int> dp[201[100001];
      |                                    ^
      |                                    ]
sequence.cpp: In function 'void dnc(int, int, int, int, int)':
sequence.cpp:11:19: error: 'dp' was not declared in this scope
   11 |   long long ans = dp[i-1][j].first + (P[mid] - P[j]) * (P[n] - P[mid]);
      |                   ^~
sequence.cpp:14:2: error: 'dp' was not declared in this scope
   14 |  dp[i][mid] = make_pair(maxx,pos);
      |  ^~
sequence.cpp: At global scope:
sequence.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:22:23: error: 'dp' was not declared in this scope
   22 |  for(int i=1;i<=n;i++)dp[1][i].first = (P[n] - P[i])*P[i];
      |                       ^~
sequence.cpp:25:26: error: 'dp' was not declared in this scope
   25 |  for(int i=1;i<=n;i++)if(dp[k][i].first > maxi)maxi = dp[k][i].first, in = i;
      |                          ^~
sequence.cpp:28:10: error: 'dp' was not declared in this scope; did you mean 'p'?
   28 |  int p = dp[k][in].second;
      |          ^~
      |          p