제출 #43708

#제출 시각아이디문제언어결과실행 시간메모리
43708baactree수열 (APIO14_sequence)C++14
100 / 100
987 ms83524 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k; ll dp[2][100005]; int par[205][100005]; ll sum[100005]; int arr[100005]; pair<ll, ll> dd[100005]; long double calc(pair<ll, ll> a, pair<ll, ll> b) { return ((long double)a.second - b.second) / (b.first - a.first); } void push(int i, int j,deque<int> &dq) { ll a = sum[j]; ll b = dp[(i-1)&1][j] - sum[j] * sum[j]; dd[j] = make_pair(a, b); while (dq.size() > 1 && (dd[dq.back()].second-dd[j].second)*(-dd[dq[dq.size() - 2]].first + dd[j].first) <= (dd[dq[dq.size() - 2]].second-dd[j].second)*(-dd[dq.back()].first + dd[j].first)) dq.pop_back(); dq.push_back(j); } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &arr[i]); sum[i] = sum[i - 1] + arr[i]; } for (int i = 1; i <= k; i++) { deque<int> dq; int cur = i & 1; int pre = (i - 1) & 1; push(i,i,dq); for (int j = i + 1; j <= n; j++) { while (dq.size() > 1 && (dd[dq[0]].second - dd[dq[1]].second) <= sum[j]*(dd[dq[1]].first-dd[dq[0]].first)) dq.pop_front(); dp[cur][j] = dd[dq[0]].first * sum[j] + dd[dq[0]].second; par[i][j] = dq[0]; push(i,j,dq); } } printf("%lld\n", dp[k & 1][n]); while (k) { printf("%d ", par[k][n]); n = par[k][n]; k--; } printf("\n"); return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:30:7: warning: unused variable 'pre' [-Wunused-variable]
   int pre = (i - 1) & 1;
       ^
sequence.cpp:22:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
sequence.cpp:24:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
                       ^
#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...