제출 #634096

#제출 시각아이디문제언어결과실행 시간메모리
634096SOCIOPATE수열 (APIO14_sequence)C++17
0 / 100
2058 ms16080 KiB
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define pll pair<ll, ll> #define pii pair<int, int> #define pdd pair<ld, ld> #define ff first #define ss second #define all(v) v.begin(),v.end() typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordset; #pragma GCC optimize("-O3") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-Os") ll INF = 2e18; ll mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll binpow(ll n, ll m){ if(m == 0) return 1ll; if(m & 1ll) return n * binpow(n, m / 2ll); ll b = binpow(n, m / 2ll); return b*b; } void solve(){ int n, k; cin >> n >> k; vector<ll> a(n), pref(n); for(int i = 0; i < n; i++) { cin >> a[i]; pref[i] = (i ? pref[i - 1] : 0) + a[i]; } vector<vector<ll>> dp(n, vector<ll>(k + 1, 0)), pr(n, vector<ll>(k + 1, -1)); auto sum = [&](int l, int r){ return pref[r] - (l ? pref[l - 1] : 0); }; for(int i = n - 2; i >= 0; i--){ for(int j = 1; j <= min(n - i - 1, k); j++){ for(int i1 = i + 1; i1 < n - j + 1; i1++){ ll newdp = sum(i, i1 - 1)*sum(i1, n - 1) + dp[i1][j - 1]; if(dp[i][j] < newdp){ pr[i][j] = i1; dp[i][j] = newdp; } } } } vector<int> ans; int lst = 0; for(int i = k; i >= 1; i--){ lst = pr[lst][k]; ans.push_back(lst - 1); } cout << dp[0][k] << '\n'; //reverse(all(ans)); for(int u : ans) cout << u + 1 << ' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif int tt; //cin >> tt; tt = 1; while (tt--) { solve(); //solve(); #ifdef LOCAL cout << "__________________________________" << endl; #endif } #ifdef LOCAL cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << "sec" << '\n'; #endif 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...