제출 #477528

#제출 시각아이디문제언어결과실행 시간메모리
477528PiejanVDC수열 (APIO14_sequence)C++17
50 / 100
2086 ms31820 KiB
#include <bits/stdc++.h> using namespace std; signed main() { int64_t n,k; cin>>n>>k; vector<int64_t>pref(n+1); pref[0]=0; for(int64_t i = 0 ; i < n ; i++) { int64_t x; cin>>x; pref[i+1] = pref[i] + x; } int64_t res[n+1][k+1]; int64_t dp[n+1][k+1]; for(int64_t i = 0 ; i <= n ; i++) dp[i][0] = 0; for(int64_t i = 1 ; i <= k ; i++) dp[0][i] = 0; for(int64_t i = 1 ; i <= k ; i++) { for(int64_t j = 1 ; j <= n ; j++) { dp[j][i] = 0; for(int64_t c = 1 ; c < j ; c++) { //assert(c-1 >= 0 && i-1 >= 0 && j-1 >= 0); if(dp[c][i-1] + (pref[n] - pref[j-1]) * (pref[j-1] - pref[c-1]) >= dp[j][i]) { res[j][i] = c; } dp[j][i] = max(dp[j][i],dp[c][i-1] + (pref[n] - pref[j-1]) * (pref[j-1] - pref[c-1])); } } } int64_t mx=0; int64_t node; vector<int64_t>ans; for(int64_t i = 0 ; i <= n ; i++) { if(dp[i][k] >= mx) { mx=dp[i][k]; node = i; } } cout << mx << "\n"; for(int i = 0 ; i < k ; i++) { cout << node-1 << " "; node = res[node][k - i]; } }

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

sequence.cpp: In function 'int main()':
sequence.cpp:42:14: warning: 'node' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |         node = res[node][k - 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...