Submission #856703

#TimeUsernameProblemLanguageResultExecution timeMemory
856703a_l_i_r_e_z_aSplit the sequence (APIO14_sequence)C++14
28 / 100
6 ms6744 KiB
// Be name Khoda // Khodaya khodet komak kon // Hope is last to die #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define pb push_back #define S second #define F first #define mp make_pair #define smax(x, y) (x) = max((x), (y)) #define smin(x, y) (x) = min((x), (y)) #define all(x) (x).begin(), (x).end() #define set_dec(x) cout << fixed << setprecision(x); #define kill(x) cout << x << endl, exit(0) #define sz(x) ((int)(x).size()) #define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); const ll maxN = 4000 + 10, inf = 1e18 + 7; ll sm[maxN], dp[2][maxN]; ll O[210][maxN]; void divide(ll k, ll l, ll r, ll optl, ll optr, ll amirG){ if(r - l < 0) return; ll mid = (l + r) / 2, op = 0; dp[k][mid] = -inf; for(int i = optl; i <= optr; i++){ ll res = dp[1 - k][i] + sm[i] * (sm[mid] - sm[i]); if(res >= dp[k][mid]) dp[k][mid] = res, op = i; } O[amirG][mid] = op; divide(k, l, mid - 1, optl, op, amirG); divide(k, mid + 1, r, op, optr, amirG); } void f(ll pos, ll k){ if(k == 0) return; f(O[k - 1][pos], k - 1); cout << pos << " "; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k; cin >> n >> k; for(int i = 0; i < n; i++){ ll x; cin >> x; sm[i + 1] = sm[i] + x; } for(int i = 1; i <= k; i++) divide(i % 2, 1, n, 0, n, i); cout << dp[k % 2][n] << '\n'; f(O[k][n], k); 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...