제출 #1290742

#제출 시각아이디문제언어결과실행 시간메모리
1290742AMel0n수열 (APIO14_sequence)C++20
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,N) for(ll i = 0; i < N; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second // APIO 14 Split The Sequence /* dp[k][m] = max score if we made k splits and the kth split was just after index m dp[k][m] = max of: dp[k-1][i] + (ps[m]-p[i-1]) * (ps[N-1]-p[m]) for all (0 <= i < m) nxt[k][m] = i where i was the optimal preceeding split point for split point m */ const ll INF = 1e18; const ll MAXN = 1e5 + 5; const ll MAXK = 205; ll N, K, PS[MAXN], dp[MAXK][MAXN], nxt[MAXK][MAXN]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; FOR(i, N) { cin >> PS[i+1]; PS[i+1] += PS[i]; } for(ll k = 1; k <= K; k++) { FOR(m, N+1) { pair<ll,ll> bsf = {-INF, -1}; for(ll i = 0; i <= m; i++) { ll bruh = dp[k-1][i] + (PS[m]-PS[i]) * (PS[N]-PS[m]); bsf = max(bsf, {bruh, i}); } dp[k][m] = bsf.F; nxt[k][m] = bsf.S; // cout << k << ' ' << m << ' ' << bsf.F << ' ' << bsf.S << ' ' << dp[k-1][bsf.S] << ' ' << PS[m] << ' ' << PS[bsf.S] << endl; } } ll mx = -INF; ll idx = -1; for(ll i = 1; i <= N; i++) { if (mx <= dp[K][i]) { mx = dp[K][i]; idx = i; } } cout << mx << endl; cout << idx << ' '; for(ll k = K; k > 1; k--) { cout << nxt[k][idx] << ' '; idx = nxt[k][idx]; } }
#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...