Submission #437577

#TimeUsernameProblemLanguageResultExecution timeMemory
437577soroushSplit the sequence (APIO14_sequence)C++17
71 / 100
2005 ms83712 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 10; int n, k; ll dp[maxn][2]; ll prt[maxn]; int par[maxn][207]; void solve(int k, int l = 1 , int r = n , int ul = 1 , int ur = n){ if(l > r)return; if(l == r){ for(int i = ul ; i <= ur and i < l ; i ++){ ll res = dp[i][!(k&1)]; res += (prt[l] - prt[i]) * (prt[n] - prt[l]); if(res > dp[l][k&1]){ dp[l][k&1] = res; par[l][k] = i; } } } int mid = (l + r) / 2; for(int i = ul ; i <= ur and i < mid ; i ++){ ll res = dp[i][!(k&1)]; res += (prt[mid] - prt[i]) * (prt[n] - prt[mid]); if(res >= dp[mid][k&1]){ dp[mid][k&1] = res; par[mid][k] = i; } } solve(k, l, mid - 1 , ul, par[mid][k]); solve(k, mid + 1 , r , par[mid][k], ur); } int32_t main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n >> k; for(int i = 1 ; i <= n ; i ++) cin >> prt[i], prt[i] += prt[i - 1]; for(int i = 1 ; i <= k ; i ++) solve(i , i , n-1 , i-1 , n-1); int ans = 1; for(int i = 1 ; i <= n ; i ++)if(dp[i][k&1] > dp[ans][k&1])ans = i; cout << dp[ans][k&1] << endl; cout << ans; while(k > 1){ cout << ' ' << par[ans][k]; ans = par[ans][k] , 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...