제출 #245156

#제출 시각아이디문제언어결과실행 시간메모리
245156thomas_li수열 (APIO14_sequence)C++17
0 / 100
2092 ms4600 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/priority_queue.hpp> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using pi = pair<int, int>; using pll = pair<ll, ll>; constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f; #ifdef __MINGW32__ inline int getchar_unlocked() { return _getchar_nolock(); } inline int putchar_unlocked(int c) { return _putchar_nolock(c); } #endif #define gc getchar_unlocked() #define pc(x) putchar_unlocked(x) template<typename T> void scan(T &x){x = 0;bool _=0; T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;} template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);} template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);} template<typename T> void print(T n){printn(n);pc(10);} template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);} #define db(x) { cerr << #x << " = " << x << endl; } template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; } template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; } #define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));} #define pb push_back #define eb emplace_back const int MM = 1e5+5; int n,k,par[205][MM]; int psa[MM], dp[205][MM]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> psa[i], psa[i] += psa[i-1]; for(int i = 1; i <= k; i++) { for(int j = 0; j <= n; j++) { for(int l = 0; l < j; l++) { ll tmp = dp[i-1][l]+(psa[j]-psa[l])*psa[l]; if(tmp > dp[i][j]) { par[i][j] = l; dp[i][j] = tmp; } } } } stack<int> st; int i = n, j = k; while(j >= 1) { i = par[j][i]; j--; st.push(i); } cout << dp[k][n] << "\n"; while(!st.empty()) { cout << st.top() << " "; st.pop(); } cout << "\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...