제출 #1319988

#제출 시각아이디문제언어결과실행 시간메모리
1319988fateless수열 (APIO14_sequence)C++20
50 / 100
79 ms4388 KiB
// #pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define now chrono::steady_clock::now().time_since_epoch().count() #define speedup cin.tie(0)->sync_with_stdio(0) #define bitcount(x) __builtin_popcountll(x) #define lla(x) x.rbegin(), x.rend() #define all(x) x.begin(), x.end() #define Tp template <class T> #define int long long #define pb push_back #define vc vector #define arr array const int inf = 1e18, N = 1e3 + 10, K = 250; Tp bool chmin (T &a, T b) {if (a > b) {a = b; return 1;} return 0;} Tp bool chmax (T &a, T b) {if (a < b) {a = b; return 1;} return 0;} static int a[N], pf[N], dp[K][N], opt[K][N]; inline void solve () { int n, kx; cin >> n >> kx; pf[0] = a[0] = 0; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) pf[i] = pf[i - 1] + a[i]; memset(dp, -1, sizeof(dp)); memset(opt, 0, sizeof(opt)); for (int i = 1; i <= n; i++) dp[0][i] = 0; for (int i = 1; i <= kx; i++) { for (int j = 2; j <= n; j++) { for (int k = j - 1; k >= 1; k--) { int val = dp[i - 1][k] + pf[k] * (pf[j] - pf[k]); if (chmax(dp[i][j], val)) opt[i][j] = k; } } } int x = n; vc<int> ans; for (int i = kx; i >= 1; i--) { x = opt[i][x]; ans.pb(x); } reverse(all(ans)); cout << dp[kx][n] << '\n'; for (int &x : ans) cout << x << ' '; } signed main() { speedup; 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...