Submission #241059

#TimeUsernameProblemLanguageResultExecution timeMemory
241059NightlightSplit the sequence (APIO14_sequence)C++14
100 / 100
1331 ms80632 KiB
#include <bits/stdc++.h> using namespace std; int N, K; long long pre[100001]; long long dp[2][100001]; int opt[201][100001]; long long cost(int l, int r) { return pre[l - 1] * (pre[r] - pre[l - 1]); } void dnc(int k, int l, int r, int kl, int kr) { if(l > r) return; long long best = -1e18, bestid = 0; int mid = (l + r) >> 1; int skg = k & 1; for(int i = kl; i <= mid && i <= kr; i++) { long long now = dp[!skg][i - 1] + cost(i, mid); if(now > best) { bestid = i; best = now; } } opt[k][mid] = bestid - 1; dp[skg][mid] = best; dnc(k, l, mid - 1, kl, bestid); dnc(k, mid + 1, r, bestid, kr); } int main() { scanf("%d %d", &N, &K); K++; for(int i = 1; i <= N; i++) { scanf("%lld", &pre[i]); pre[i] += pre[i - 1]; } for(int i = 2; i <= K; i++) { dnc(i, i, N, i, N); } printf("%lld\n", dp[K & 1][N]); int now = N; vector<int> ans; for(int i = K; i > 1; i--) { now = opt[i][now]; ans.push_back(now); } for(int i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]); puts(""); cin >> N; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &K);
   ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &pre[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...