Submission #681745

#TimeUsernameProblemLanguageResultExecution timeMemory
681745vjudge1Split the sequence (APIO14_sequence)C++14
28 / 100
2089 ms18424 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(a) a.begin(), a.end() typedef long long ll; typedef pair<int, int> ii; void print() {cerr << '\n';} template <typename T1, typename... T2> void print(const T1 &a, const T2 &...b) { cerr << a << ' ', print(b...); } const int N = 1e4 + 5; const int mod = 1e9 + 7; int n, k; ll a[N]; ll dp[205][N]; int trace[205][N]; void solve() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; for(int i = 0; i <= k; i++) for(int j = 0; j <= n; j++) dp[i][j] = -1e17; dp[0][0] = 0; for(int i = 1; i <= k; i++) for(int j = n; j >= i; j--) // ket thuc tai j for(int u = j; u >= i; u--) // bat dau tai u { ll back = a[n] - a[j]; ll front = a[j] - a[u - 1]; if(dp[i][j] < dp[i - 1][u - 1] + front * back) { dp[i][j] = dp[i - 1][u - 1] + front * back; trace[i][j] = u - 1; } } int pos = 0; ll mx = -1e17; for(int i = 1; i <= n; i++) if(mx <= dp[k][i]) mx = dp[k][i], pos = i; deque<int> res; for(int i = k; i >= 1; i--) { res.push_front(pos); pos = trace[i][pos]; assert((int)res.size() <= k); } cout << mx << '\n'; for(const int &x : res) cout << x << ' '; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#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...