제출 #1116729

#제출 시각아이디문제언어결과실행 시간메모리
1116729monaxia수열 (APIO14_sequence)C++17
0 / 100
68 ms68948 KiB
#include <bits/stdc++.h> #define pb push_back #define ppb pop_back #define fr first #define sc second #define all(v) v.begin(), v.end() #define mod (long long)(1e9 + 7) #define eps (long long)(1e-9) #define vektor vector using namespace std; using ll= long long; using ull= unsigned long long; using ld = long double; const ull Mod = 1e9 + 7; unsigned pre[100005], dp[205][100005]; int where[205][100005]; int n, k; unsigned cost(int l, int r){ return (pre[r] - pre[l - 1]) * pre[l - 1]; } void dp_do(int l, int r, int optl, int optr, int layer){ if(l > r) return; pair <ll, int> best(0, 1); int mid = (l + r) >> 1; for(int i = optl; i <= min(mid, optr); i ++){ best = max(best, {dp[layer - 1][i - 1] + cost(i, mid), i}); // cout << cost(i, mid) << "\n"; } // if(mid == 2 && layer == 1) cout << best.fr << ' ' << best.sc << "\n"; // cout << layer << " " << mid << " " << best.fr << " " << best.sc << '\n'; dp[layer][mid] = best.fr; where[layer][mid] = best.sc; // if(where[layer][mid] == 1 && layer == 1) cout << mid << " " << layer << " " << dp[layer][mid] << "\n"; int opt = best.sc; dp_do(l, mid - 1, optl, opt, layer); dp_do(mid + 1, r, opt, optr, layer); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i ++){ unsigned x; cin >> x; pre[i] = pre[i - 1] + x; } for(int i = 1; i <= k; i ++) dp_do(1, n, 1, n, i); cout << dp[k][n] << "\n"; vector <int> ans; for(int i = n; k >= 1; k --){ // cout << i << " " << k << " " << where[k][i] - 1 << "\n"; // cout << dp[k][i] << " " << dp[k][i] - cost(where[k][i], i) << "\n"; i = where[k][i] - 1; ans.pb(i); } reverse(all(ans)); for(auto& x : ans) cout << x << " "; } signed main() { cin.tie(0)->sync_with_stdio(0); // if(fopen("blank.inp", "r")){ // freopen("blank.inp", "r", stdin); // freopen("blank.out", "w", stdout); // } // // cout << 1; return 0; unsigned n = 1; // cin >> n; while(n) { solve(); n --; cout << "\n"; } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } // ++++ // ++++-::......:--:::-=+++ // ++++=:............---.....--:..:=++++++ // +++++++::......................::=+++++ // @@ ++++++++++:+++++++++ // @% @* // %%@@ *****#*@@ // %%%%% @##**##***% // @@@@@@+-*#*@ #####%+*##*@ // %#+@%%@@@ ##-%:::-#*###@@ // =====:*::: ###-:==::=#*%* // -====:::::+@@%@@%@#*--=*#%%#@%@ @%@ // @=====%=-@%=:::.:+-::::+::::::::::::%-----%% @@@@@ // @@%#*@++%===+::-================@%@@@@+++++++@@@%%%@#%###% // @#***#@@ @##=%@===+--:+==+===+%*##@%%%@@@@@@@@@@:= @%@%%%@#%% // -@ @*#@ #####%:::-====+:::==---**%#@ *%%%%@@@@@@-: // -=-*% # #***--%%::::::::+=-+#-----=**@*# #+**#@# // ----=----#+****=----=*#@=::::::=#-----------***%*% // ------------%*****##=@==::::::+%-----------***%** // +-----------------*@++%::::::::-----------****@*# // =------------% @%=+%#+:::::::* #-----*--**** ** // ----%--% *==+++++=+=##*:% ---=--**** ** // %@@@@@@@@@==@+%%%%@ ----**** *# // @=*+%@@@%@@=++=:%:::% #***@@# // #+++++++++#==++-:::::: @**** *# // =+++++++++++==+++::::::: ####@ #% // +++++++++++=@ @++++::::::@ @# // @+++++++++=@ =*++=:::::@ // ++++++++@ @++++::::: // ++++++= =++++::: // =+++++@ =+++:::: // ++++++-@ =+++:+:: // @::+::::@ =++::-::: // +::=::::: @+*+:-+++-: // @::+-:::::# +++::::::@ // ::%=:::::::%@ @%++::::*** // @:+@*:::::::****@ +@+++:-=*:*@ // *:@@%::::::::=**** @%@+++:::#**@ // *%@@@-:::::::%=+==*@ +@%+++:***+* // #%@@%%::::::::#+=-=# =+@+++++:::*+ // @####+::::::::%+=@#%#=@ @**@@%=++::::@ // @ +:::::::::***#*@ @@###+=+=%@ +**#+=+*+:::- // =-:::::::%%%%@@ @#=*########%#+*%%+--@*+::% // +---%@ @@ =-:-**:# // %%%%% @+--*@ // @%%%%@ @%%%%% // @%%@@
#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...