제출 #416236

#제출 시각아이디문제언어결과실행 시간메모리
416236DEQK수열 (APIO14_sequence)C++17
71 / 100
2075 ms81304 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 100100; int n, k; ll a[N]; ll dp[N][2]; int p[N][201]; int cur; void solve(int l,int r,int tl,int tr) { if(l > r) return; int m = l + r >> 1; for(int i = tl; i < min(m, tr + 1); i++) { if(dp[m][1] <= dp[i][0] + a[i] * 1ll * (a[m] - a[i])) { dp[m][1] = dp[i][0] + a[i] * 1ll * (a[m] - a[i]); p[m][cur] = i; } } solve(l, m - 1, tl, p[m][cur]); solve(m + 1, r, p[m][cur], tr); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; a[i] += a[i - 1]; } for(int j = 1; j <= k; j++) { cur = j; solve(1, n, 1, n); for(int i = 1; i <= n; i++) { dp[i][0] = dp[i][1]; dp[i][1] = 0; } } cout << dp[n][0] << "\n"; int pos = n; for(int j = k; j; j--) { cout << p[pos][j] << " "; pos = p[pos][j]; } }

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

sequence.cpp: In function 'void solve(int, int, int, int)':
sequence.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |  int m = l + r >> 1;
      |          ~~^~~
#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...