제출 #319921

#제출 시각아이디문제언어결과실행 시간메모리
319921tushar_2658수열 (APIO14_sequence)C++14
71 / 100
2033 ms82660 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 100005; using ll = long long; ll dp[maxn][2]; int n, k; ll a[maxn], pref[maxn]; int best[maxn][202]; int cur, cnt; void compute(int l, int r, int optl, int optr){ if(l > r)return; int mid = (l + r) >> 1; int opt = optl; for(int i = optl; i <= min(mid - 1, optr); ++i){ ll cost = dp[i][cur ^ 1] + pref[i] * (pref[mid] - pref[i]); if(dp[mid][cur] < cost){ dp[mid][cur] = cost; opt = i; } } best[mid][cnt] = opt; compute(l, mid - 1, optl, opt); compute(mid + 1, r, opt, optr); } int main(int argc, char const *argv[]) { scanf("%d %d", &n, &k); for(int i = 1; i <= n; ++i){ scanf("%lld", &a[i]); pref[i] = pref[i - 1] + a[i]; } for(int i = 1; i <= k; ++i){ cur = i & 1; cnt = i; for(int j = 0; j <= n; ++j){ dp[j][cur] = -1; } compute(1, n, 1, n); } printf("%lld\n", dp[n][k & 1]); cur = n; int cur_k = k; while(cur_k > 0){ printf("%d ", best[cur][cur_k]); cur = best[cur][cur_k]; --cur_k; } return 0; }

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

sequence.cpp: In function 'int main(int, const char**)':
sequence.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   scanf("%d %d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |     scanf("%lld", &a[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...