제출 #406483

#제출 시각아이디문제언어결과실행 시간메모리
406483yoavL수열 (APIO14_sequence)C++14
0 / 100
2058 ms8920 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <bitset> #include <math.h> #include <fstream> #include <iomanip> using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vvvvll = vector<vvvll>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using vld = vector<ld>; using vvld = vector<vld>; using vstr = vector<string>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>; using pb = pair<bool, bool>; using vpb = vector<pb>; using vvpb = vector<vpb>; using vi = vector<int>; using vvi = vector<vi>; const ll mod = (ll)1e9 + 7; const ll inf = (ll)1e18; #define FAST ios_base::sync_with_stdio(0) #define FASTIN cin.tie(0) #define FASTOUT cout.tie(0) #define upmin(a, b) a = min(a, b) #define upmax(a, b) a = max(a, b) #define pr(x) cout << x << endl; #define prv(v) for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl; #define prvv(v) for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl; #define wpr(x) cout << #x << " = " << (x) << endl; #define wprv(v) cout << #v << ": " << endl; for(auto it : v) cout << *it << " "; cout << endl; #define wprvv(v) cout << #v << ": " << endl; for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl; #define rep(i,s,e) for(ll i = s; i < e; i++) #define all(x) x.begin(),x.end() #define pb push_back ll n, k; vll arr; vvll dp, last; vll p; /* dp[layer][i] = max sum using layer seperators and i is the last one (and it is AFTER i) */ void solve() { cin >> n >> k; if (k + 1 == n) { cout << 0 << endl; return; } arr.resize(n); rep(i, 0, n) cin >> arr[i]; p.resize(n); p[0] = arr[0]; rep(i, 1, n) p[i] = arr[i] + p[i - 1]; dp.resize(k + 1, vll(n - 1, 0)); last.resize(k + 1, vll(n - 1, -1)); rep(i, 0, n - 1) { dp[1][i] = p[i] * (p[n - 1] - p[i]); } rep(l, 2, k + 1) { rep(i, 0, n-1) { rep(j, 0, i - 1) { ll v = dp[l - 1][j] + (p[i] - p[j])*(p[n-1] - p[i]); if (dp[l][i] < v) { dp[l][i] = v; last[l][i] = j; } } } } wprvv(dp); ll ans = -1; ll mxind = -1; rep(i, 0, n-1) { if (dp[k][i] > ans) { ans = dp[k][i]; mxind = i; } } vll used; ll cur = mxind; ll left = k; while (cur != -1) { used.push_back(cur+1); cur = last[left][cur]; left--; } reverse(used.begin(), used.end()); //used.pop_back(); pr(ans); prv(used); } int main() { FAST; FASTIN; FASTOUT; solve(); } /* 7 3 4 1 3 4 0 2 3 */
#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...