제출 #416213

#제출 시각아이디문제언어결과실행 시간메모리
416213DEQK수열 (APIO14_sequence)C++17
49 / 100
115 ms131076 KiB
#pragma GCC optimize("O3") #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], p[N][201], opt[N]; int cur; ll cost(int i,int j) { 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] = -1e17; } 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++) { cur = j; solve(1, n, 1, n); for(int i = 1; i <= n; ++i) { dp[i][0] = dp[i][1]; p[i][j] = opt[i]; } } cout << dp[n][1] << "\n"; for(int j = k, cur = n; j; --j) { cout << p[cur][j] << ' '; cur = p[cur][j]; } }

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

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