Submission #744966

#TimeUsernameProblemLanguageResultExecution timeMemory
744966zeta7532Split the sequence (APIO14_sequence)C++17
28 / 100
2072 ms48220 KiB
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; const ll mod = 998244353; #define fi first #define se second #define rep(i,n) for(ll i=0;i<n;i++) #define all(x) x.begin(),x.end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr) int main() { ll N,K; cin >> N >> K; K++; vector<ll> A(N); rep(i,N) cin >> A[i]; vector<ll> sum(N+1); sum[0]=0; rep(i,N) sum[i+1]=sum[i]+A[i]; vector<vector<ll>> dp(N+1,vector<ll>(K+1,0)); ll ans[N+1][K+1][2]; rep(i,N){ rep(k,K){ dp[i+1][k+1]=-1; rep(j,i+1){ ll x=dp[j][k]+(sum[i+1]-sum[j])*(sum[N]-sum[i+1]); if(dp[i+1][k+1]<x){ dp[i+1][k+1]=x;; ans[i+1][k+1][0]=j; ans[i+1][k+1][1]=k; } } } } cout << dp[N][K] << endl; ll y=N,z=K; vector<ll> ANS; while(1){ ll ny=ans[y][z][0]; ll nz=ans[y][z][1]; y=ny; z=nz; if(y==0) break; ANS.push_back(y); } reverse(all(ANS)); rep(i,ANS.size()) cout << ANS[i] << " "; cout << endl; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:10:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define rep(i,n) for(ll i=0;i<n;i++)
......
   50 |     rep(i,ANS.size()) cout << ANS[i] << " ";
      |         ~~~~~~~~~~~~          
sequence.cpp:50:5: note: in expansion of macro 'rep'
   50 |     rep(i,ANS.size()) cout << ANS[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...