제출 #416234

#제출 시각아이디문제언어결과실행 시간메모리
416234DEQK수열 (APIO14_sequence)C++17
0 / 100
34 ms4156 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 5, K = 205; const ll INF = numeric_limits<ll>::max(); int n, k; ll a[N]; ll dp[N][2]; int p[K][N]; int opt[N]; ll cost(int i,int j) { assert(j < i); return dp[j][0] + a[j] * (a[i] - a[j]); } void solve(int l,int r,int tl,int tr) { if(l > r) return; int m = l + r >> 1; opt[m] = -1; for(int j = tl; j <= min(m - 1, tr); ++j) { if(opt[m] == -1 || cost(m, opt[m]) < cost(m, j)) { opt[m] = j; } } if(opt[m] == -1) { dp[m][1] = -INF; } else { dp[m][1] = cost(m, opt[m]); } solve(l, m - 1, tl, opt[m]); solve(m + 1, r, opt[m], 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++) { dp[0][0] = -INF; for(int i = 1; i <= n; i++) { dp[i][0] = dp[i][1]; } solve(1, n, 1, n); for(int i = 1; i <= n; ++i) { p[j][i] = opt[i]; } } cout << dp[n][1] << "\n"; for(int i = k, cur = n; i; i--) { cout << p[i][cur]; cur = p[i][cur]; } }

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

sequence.cpp: In function 'void solve(int, int, int, int)':
sequence.cpp:18:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |  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...