제출 #569539

#제출 시각아이디문제언어결과실행 시간메모리
569539SAAD수열 (APIO14_sequence)C++17
0 / 100
61 ms131072 KiB
#define F first #define S second #define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1)) #define pb push_back #define Fbitl __builtin_ffs #define bit1 __builtin_popcount #include <iostream> #include <math.h> #include <algorithm> #include <string.h> #include <vector> #include <queue> #include <map> #include <unordered_map> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; ll x[100005] , c[100005] ; pair<ll, ll> dp[100002][202]; int n; pair<ll,ll> calc ( int idx , int k ) { if (dp[idx][k].F != -1) return dp[idx][k]; if (k == 0) return dp[idx][k] = { 0,-1 }; for (int i = n-k; i >= idx; i--) { ll resi = calc(i + 1, k - 1).F; ll a = (c[n]-c[i]) * (c[i]-c[idx-1]); //cout << idx << ":" << i << " " << k << " " << a << endl ; resi += a; if (dp[idx][k].first < resi) { dp[idx][k] = { resi, i+1 }; } } return dp[idx][k]; } int main() { int k; cin >> n >> k; memset(dp,-1,sizeof(dp)); for (int i = 1; i <= n; i++) { cin >> x[i]; c[i] += c[i - 1] + x[i]; } cout << calc(1, k).F << endl ; vi res; int a = dp[1][k].S; while ( k > 0 ) { res.push_back(a); k--; a = dp[a][k].S; } for (auto i : res) cout << i-1 << " "; 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...