Submission #863528

#TimeUsernameProblemLanguageResultExecution timeMemory
863528SyedShajibSplit the sequence (APIO14_sequence)C++17
0 / 100
2095 ms13400 KiB
#include <iostream> #include <vector> #include <algorithm> int main() { int n, k; std::cin >> n >> k; std::vector<int> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } std::vector<std::vector<long long>> dp(n + 1, std::vector<long long>(k + 1, -1)); std::vector<std::vector<int>> pos(n + 1, std::vector<int>(k + 1, -1)); dp[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j <= k; ++j) { if (dp[i][j] != -1) { long long sum = 0; for (int l = i; l < n; ++l) { sum += a[l]; if (j + 1 <= k && dp[l + 1][j + 1] < dp[i][j] + sum * (l - i + 1)) { dp[l + 1][j + 1] = dp[i][j] + sum * (l - i + 1); pos[l + 1][j + 1] = i; } } } } } std::cout << dp[n][k] << std::endl; int cur = n, curk = k; std::vector<int> splits; while (cur > 0) { splits.push_back(pos[cur][curk]); cur = pos[cur][curk]; --curk; } std::reverse(splits.begin(), splits.end()); for (int i = 0; i < splits.size() - 1; ++i) { std::cout << splits[i] << ' '; } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < splits.size() - 1; ++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...