Submission #1293628

#TimeUsernameProblemLanguageResultExecution timeMemory
1293628trandaihao5555Split the sequence (APIO14_sequence)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> //#define int long long #define debug cout << "ok\n"; #define SQR(x) (1LL * ((x) * (x))) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define fi first #define se second #define pb push_back #define mp make_pair #define pii pair<int,int> #define pli pair<ll,int> #define vi vector<int> #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef unsigned int ui; using namespace std; const int M = 1e9 + 7; const int INF = 1e9 + 7; const ll INFLL = (ll)2e18 + 7LL; const ld PI = acos(-1); const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1}; const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1}; template<class _, class __> bool minimize(_ &x, const __ y){ if(x > y){ x = y; return true; } else return false; } template<class _, class __> bool maximize(_ &x, const __ y){ if(x < y){ x = y; return true; } else return false; } template<class _,class __> void Add(_ &x, const __ y) { x += y; if (x >= M) { x -= M; } return; } template<class _,class __> void Diff(_ &x, const __ y) { x -= y; if (x < 0) { x += M; } return; } //-------------------------------------------------------------- const int MaxN = 1e6+7; const int MaxK = 207; vi dp_be,dp_af,trace[MaxK]; int n,k,a[MaxN]; int sum(int l,int r) { return a[r] - a[l-1]; } void dnc(int l,int r,int ls,int rs,vi & trace) { if (l > r) return; int mid = (l + r) >> 1; for (int i=ls;i<mid && i <= rs;i++) { if (maximize(dp_af[mid],dp_be[i] + 1LL*sum(i+1,mid) * a[i])) trace[mid] = i; } dnc(l,mid-1,ls,trace[mid],trace); dnc(mid+1,r,trace[mid],rs,trace); } void sol() { cin >> n >> k; k++; for (int i=1;i<=n;i++) cin >> a[i],a[i] += a[i-1]; dp_be.resize(n+1,-INFLL); dp_af.resize(n+1,-INFLL); dp_af[0] = 0; trace[0].resize(n+1); for (int i=1;i<=k;i++) { trace[i] = trace[0]; } for (int i=1;i<=k;i++) { swap(dp_be,dp_af); for (int & x : dp_af) x = -INFLL; dnc(i,n,i-1,n,trace[i]); } cout << dp_af[n] << '\n'; int tmp = trace[k--][n]; while (k) { cout << tmp << ' '; tmp = trace[k][tmp]; k--; } } signed main() { // freopen("test.inp","r",stdin); // freopen("test.out","w",stdout); FAST int t=1; // cin >> t; while (t--) sol(); }

Compilation message (stderr)

sequence.cpp: In function 'void sol()':
sequence.cpp:95:22: warning: overflow in conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '-2000000000000000007' to '-1321730055' [-Woverflow]
   95 |     dp_be.resize(n+1,-INFLL);
      |                      ^~~~~~
sequence.cpp:96:22: warning: overflow in conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '-2000000000000000007' to '-1321730055' [-Woverflow]
   96 |     dp_af.resize(n+1,-INFLL);
      |                      ^~~~~~
sequence.cpp:104:35: warning: overflow in conversion from 'long long int' to 'int' changes value from '-2000000000000000007' to '-1321730055' [-Woverflow]
  104 |         for (int & x : dp_af) x = -INFLL;
      |                                   ^~~~~~
#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...