제출 #26479

#제출 시각아이디문제언어결과실행 시간메모리
26479zoomswk수열 (APIO14_sequence)C++14
100 / 100
1796 ms83540 KiB
#include <stdio.h> int min(int a, int b){ return a < b ? a : b; } int n; long long a[100005]; long long dp[100005][2]; int opt[100005][205]; void conquer(int l, int r, int lv, int opt_l, int opt_r){ if(l > r) return; int mid = (l+r)>>1; for(int i=opt_l; i<=min(mid-1, opt_r); i++){ long long val = dp[i][(lv-1)&1] + (a[mid]-a[i])*(a[n]-a[mid]); if(val >= dp[mid][lv&1]) dp[mid][lv&1] = val, opt[mid][lv] = i; } conquer(l, mid-1, lv, opt_l, opt[mid][lv]); conquer(mid+1, r, lv, opt[mid][lv], opt_r); return; } int main(){ int k; scanf("%d%d", &n, &k); for(int i=1; i<=n; i++) scanf("%lld", &a[i]), a[i] += a[i-1]; for(int i=1; i<=k; i++){ for(int j=1; j<=n; j++) dp[j][i&1] = 0; conquer(1, n, i, 0, n); } long long res = 0; int res_pos = 0; for(int i=1; i<n; i++){ if(dp[i][k&1] >= res){ res = dp[i][k&1]; res_pos = i; } } printf("%lld\n", res); while(k){ printf("%d ", res_pos); res_pos = opt[res_pos][k]; k--; } return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:24:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
                          ^
sequence.cpp:25:65: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=n; i++) scanf("%lld", &a[i]), a[i] += a[i-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...