Submission #36438

#TimeUsernameProblemLanguageResultExecution timeMemory
36438ToMoCloneSplit the sequence (APIO14_sequence)C++14
89 / 100
1783 ms82800 KiB
/*input 7 3 4 1 3 4 0 2 3 */ #include <vector> #include <stdio.h> #include <algorithm> using namespace std; vector<long long> ans, val, sum; int n, k, trace[201][100001]; void solve(int step, int l, int r, int u, int v){ int mid = (l + r) >> 1; ans[mid] = 0; for(int i = u; i <= min(mid, v); ++i) if(ans[mid] <= 1ll * sum[i] * (sum[mid] - sum[i]) + val[i]) ans[mid] = 1ll * sum[i] * (sum[mid] - sum[i]) + val[i], trace[step][mid] = i; if(l == r) return; solve(step, l, mid, u, trace[step][mid]); solve(step, mid + 1, r, trace[step][mid], v); } int main(){ scanf("%d%d", &n, &k); sum.resize(n + 1), ans.resize(n + 1), val.resize(n + 1); for(int i = 1; i <= n; ++i) scanf("%lld", &sum[i]), sum[i] += sum[i - 1]; for(int i = 1; i <= k; ++i) ans.swap(val), solve(i, 1, n, 1, n - 1); printf("%lld\n", ans[n]); vector<int> res; while(k != 0 && n != 0) res.push_back(trace[k][n]), n = trace[k--][n]; sort(res.begin(), res.end()); res.erase(unique(res.begin(), res.end()), res.end()); for(int i = 0; i < (int)res.size(); ++i) printf("%s%d", i ? " " : "", res[i]); }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:27:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
sequence.cpp:30:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &sum[i]), sum[i] += sum[i - 1];
                                               ^
#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...