Submission #209962

#TimeUsernameProblemLanguageResultExecution timeMemory
209962my99n수열 (APIO14_sequence)C++14
71 / 100
2102 ms112244 KiB
#include<bits/stdc++.h> using namespace std; long long a[100100], s[100100], dp[2][100100]; vector<int> mxk[2][100100]; void solve (int i, int l, int r, int kmin, int kmax) { if (r < l) return; int mid = (l+r)/2, m = -1; for (int k = kmin; k <= min(kmax, mid-1); k++) { long long nw = dp[i^1][k] + (s[mid]-s[k])*(s[k]-s[0]); if (nw >= dp[i][mid]) { dp[i][mid] = nw; m = k; } } mxk[i][mid].clear(); mxk[i][mid].push_back(m); for (auto x : mxk[i^1][m]) mxk[i][mid].push_back(x); solve(i, l, mid-1, kmin, m); solve(i, mid+1, r, m, kmax); } int main(){ int n, k; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), s[i] = s[i-1]+a[i]; for (int i = 1; i <= k; i++) solve(i%2, 1, n, 1, n-1); printf("%lld\n", dp[k%2][n]); for (auto x : mxk[k%2][n]) printf("%d ", x); return 0; } // 7 3 4 1 3 4 0 2 3

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:24:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n, k; scanf("%d %d", &n, &k);
               ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:25:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), s[i] = s[i-1]+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...