제출 #41634

#제출 시각아이디문제언어결과실행 시간메모리
41634funcsr수열 (APIO14_sequence)C++14
50 / 100
2045 ms32716 KiB
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cassert> #include <map> using namespace std; #define int long long typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(x) x.begin(), x.end() #define uniq(x) x.erase(unique(all(x)), x.end()) #define index(x, y) (int)(lower_bound(all(x), y) - x.begin()) #define _1 first #define _2 second #define pb push_back #define MOD 1000000007 #define INF (1LL<<60) int N, K; int B[10001]; long long dp[10001][202]; int pre[10001][202]; signed main() { cin >> N >> K; K++; rep(i, N) cin >> B[i+1]; rep(i, N) B[i+1] += B[i]; rep(i, N+1) rep(j, K+1) dp[i][j] = INF, pre[i][j] = -1; dp[0][0] = 0; for (int x=1; x<=N; x++) { rep(k, K) { rep(y, x) { if (dp[y][k] == INF) continue; long long v = 1LL*B[x]*B[x] + (dp[y][k] + 1LL*B[y]*B[y] - 2LL*B[x]*B[y]); if (dp[x][k+1] > v) { dp[x][k+1] = v; pre[x][k+1] = y; } } } } long long m = (1LL*B[N]*B[N]-dp[N][K])/2LL; cout << m << "\n"; int p = pre[N][K], k = K-1; vector<int> seq; while (k > 0) { seq.pb(p); p = pre[p][k]; k--; } reverse(all(seq)); for (int x : seq) cout << x << " "; cout << "\n"; 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...