Submission #35099

#TimeUsernameProblemLanguageResultExecution timeMemory
35099UncleGrandpa925Split the sequence (APIO14_sequence)C++14
0 / 100
0 ms1840 KiB
/*input 7 3 4 1 3 4 0 2 3 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define N 100005 #define bit(x,y) ((x>>y)&1LL) #define na(x) (#x) << ":" << x ostream& operator << (ostream &os, vector<int>&x) { for (int i = 0; i < x.size(); i++) os << x[i] << sp; return os; } ostream& operator << (ostream &os, pair<int, int> x) { cout << x.fi << sp << x.se << sp; return os; } ostream& operator << (ostream &os, vector<pair<int, int> >&x) { for (int i = 0; i < x.size(); i++) os << x[i] << endl; return os; } int n, m; int a[N]; int sum[N]; int dp[N][205]; int par[N][205]; vector<int> order; signed main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i]; for (int i = 1; i <= n; i++) dp[i][0] = 0; for (int p = 1; p <= m; p++) { dp[1][p] = sum[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { if (dp[j][p - 1] + sum[j] * (sum[i] - sum[j]) > dp[i][p]) { dp[i][p] = dp[j][p - 1] + sum[j] * (sum[i] - sum[j]); par[i][p] = j; } } } } printf("%d\n", dp[n][m]); pair<int, int> cur = mp(n, m); while (cur.se >= 1) { order.push_back(par[cur.fi][cur.se]); cur.fi = par[cur.fi][cur.se]; cur.se--; } reverse(order.begin(), order.end()); for (int i = 0; i < order.size(); i++) printf("%d ", order[i]); }

Compilation message (stderr)

sequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
sequence.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
sequence.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<int, int> >&)':
sequence.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
sequence.cpp: In function 'int main()':
sequence.cpp:57:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < order.size(); i++) printf("%d ", order[i]);
                    ^
sequence.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
sequence.cpp:36:77: 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("%d", &a[i]), sum[i] = sum[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...