Submission #93265

#TimeUsernameProblemLanguageResultExecution timeMemory
93265emil_physmathSplit the sequence (APIO14_sequence)C++17
50 / 100
2062 ms53536 KiB
#include <iostream> #include <stdio.h> using namespace std; const int MAXN=100001, MAXK=301; long long a[MAXN], prefSum[MAXN], dp[MAXN][MAXK]; int lt[MAXN][MAXK]; long long sum(int l, int r); int main() { int n, k; cin>>n>>k; for (int i=0; i<n; i++) scanf("%lld", a+i); prefSum[0]=a[0]; for (int i=1; i<n; i++) prefSum[i]=prefSum[i-1]+a[i]; for (int i=0; i<n; i++) for (int curk=1; curk<=min(k, i); curk++) { dp[i][curk]=lt[n-1][curk]=-1; for (int prevSpl=curk-1; prevSpl<i; prevSpl++) { long long curDP=dp[prevSpl][curk-1]+sum(0, prevSpl)*sum(prevSpl+1, i); if (curDP>dp[i][curk]) { dp[i][curk]=curDP; lt[i][curk]=prevSpl; } } } cout<<dp[n-1][k]<<'\n'; int cur=n-1; int cnt=0; while (k) { cur=lt[cur][k]; k--; printf("%d ", cur+1); cnt++; } cout<<'\n'; char I; cin >> I; return 0; } long long sum(int l, int r) { return l ? prefSum[r]-prefSum[l-1] : prefSum[r]; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", a+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...