제출 #1116691

#제출 시각아이디문제언어결과실행 시간메모리
1116691monaxia수열 (APIO14_sequence)C++17
0 / 100
105 ms131072 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 unsigned Mod = 1e9 + 7; ll pre[100005], dp[205][100005], place[205][100005]; int n, k; ll cost(int l, int r){ return (pre[r] - pre[l - 1]) * pre[l - 1]; } bool comp(pair <ll, int>& a, pair <ll, int> b){ if(a.fr != b.fr) return a.fr < b.fr; return a.sc < b.sc; } 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 ++){ // cout << comp(best, {dp[layer - 1][i - 1] + cost(i, mid), i}) << " " << best.fr << " " << dp[layer - 1][i - 1] + cost(i, mid) << "\n"; if(comp(best, {dp[layer - 1][i - 1] + cost(i, mid), i})) best = {dp[layer - 1][i - 1] + cost(i, mid), i}; } // cout << layer << " " << mid << " " << best.fr << "\n"; dp[layer][mid] = best.fr; int opt = best.sc; place[layer][mid] = best.sc; // dp_do(l, mid - 1, optl, opt, layer); dp_do(mid + 1, r, opt, optr, layer); } void solve(){ memset(dp, 0, sizeof(dp)); dp[0][0] = 0; cin >> n >> k; for(int i = 1; i <= n; i ++){ ll 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"; int cur = n; vector <int> ans; for(; k >= 1; k --){ ans.pb(place[k][cur] - 1); cur = place[k][cur] - 1; } 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; ll n = 1; // cin >> n; while(n) { solve(); n --; cout << "\n"; } cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } // ++++ // ++++-::......:--:::-=+++ // ++++=:............---.....--:..:=++++++ // +++++++::......................::=+++++ // @@ ++++++++++:+++++++++ // @% @* // %%@@ *****#*@@ // %%%%% @##**##***% // @@@@@@+-*#*@ #####%+*##*@ // %#+@%%@@@ ##-%:::-#*###@@ // =====:*::: ###-:==::=#*%* // -====:::::+@@%@@%@#*--=*#%%#@%@ @%@ // @=====%=-@%=:::.:+-::::+::::::::::::%-----%% @@@@@ // @@%#*@++%===+::-================@%@@@@+++++++@@@%%%@#%###% // @#***#@@ @##=%@===+--:+==+===+%*##@%%%@@@@@@@@@@:= @%@%%%@#%% // -@ @*#@ #####%:::-====+:::==---**%#@ *%%%%@@@@@@-: // -=-*% # #***--%%::::::::+=-+#-----=**@*# #+**#@# // ----=----#+****=----=*#@=::::::=#-----------***%*% // ------------%*****##=@==::::::+%-----------***%** // +-----------------*@++%::::::::-----------****@*# // =------------% @%=+%#+:::::::* #-----*--**** ** // ----%--% *==+++++=+=##*:% ---=--**** ** // %@@@@@@@@@==@+%%%%@ ----**** *# // @=*+%@@@%@@=++=:%:::% #***@@# // #+++++++++#==++-:::::: @**** *# // =+++++++++++==+++::::::: ####@ #% // +++++++++++=@ @++++::::::@ @# // @+++++++++=@ =*++=:::::@ // ++++++++@ @++++::::: // ++++++= =++++::: // =+++++@ =+++:::: // ++++++-@ =+++:+:: // @::+::::@ =++::-::: // +::=::::: @+*+:-+++-: // @::+-:::::# +++::::::@ // ::%=:::::::%@ @%++::::*** // @:+@*:::::::****@ +@+++:-=*:*@ // *:@@%::::::::=**** @%@+++:::#**@ // *%@@@-:::::::%=+==*@ +@%+++:***+* // #%@@%%::::::::#+=-=# =+@+++++:::*+ // @####+::::::::%+=@#%#=@ @**@@%=++::::@ // @ +:::::::::***#*@ @@###+=+=%@ +**#+=+*+:::- // =-:::::::%%%%@@ @#=*########%#+*%%+--@*+::% // +---%@ @@ =-:-**:# // %%%%% @+--*@ // @%%%%@ @%%%%% // @%%@@

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen("blank.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen("blank.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...