제출 #1110104

#제출 시각아이디문제언어결과실행 시간메모리
1110104sunboi수열 (APIO14_sequence)C++17
50 / 100
2041 ms16488 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; signed main(){ int n, k; cin >> n >> k; vector<int> a(n + 1), suf(n + 2); for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = n; i >= 0; i--){ suf[i] = suf[i + 1] + a[i]; } vector<vector<int>> dp(n + 10, vector<int> (k + 1, 0)); for (int i = n; i >= 1; i--){ for (int j = i + 1; j <= n; j++){ int suma = suf[i] - suf[j]; int before = suf[j]; for (int kk = 1; kk <= k; kk++){ dp[i][kk] = max(dp[i][kk], dp[j][kk - 1] + suma * before); } } } set<int> id; int last = 1; int kk = k; for (int i = 2; i <= n; i++){ //cout << last << ' ' << kk << endl; int suma = suf[last] - suf[i]; int before = suf[i]; if (dp[last][kk] == dp[i][kk - 1] + suma * before){ id.insert(i - 1); last = i; kk--; } } cout << dp[1][k] << endl; for (int x : id) cout << x << ' '; cout << endl; }
#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...