제출 #107273

#제출 시각아이디문제언어결과실행 시간메모리
107273abil수열 (APIO14_sequence)C++14
11 / 100
79 ms9320 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int)100007; int n, k, par[207][N]; long long dp[3][N]; int arr[N]; long long f(int l,int r){ return arr[l] * (arr[r] - arr[l]); } void solve(int g,int l,int r,int optl,int optr){ if(l > r){ return; } int mid = (l + r) >> 1, opt; for(int i = optl; i <= min(optr,mid - 1); i++){ if(dp[(g % 2)][mid] <= dp[(g - 1) % 2][i] + f(i,mid)){ dp[(g % 2)][mid] = dp[(g - 1) % 2][i] + f(i,mid); opt = i; } } par[g][mid] = opt; solve(g,l,mid - 1, optl, opt); solve(g,mid + 1, r, opt, optr); } main(){ scanf("%d %d",&n, &k); for(int i = 1;i <= n; i++){ scanf("%d", &arr[i]); arr[i] = arr[i - 1] + arr[i]; } for(int i = 1;i <= k; i++){ solve(i,1,n,1,n - 1); } printf("%lld\n",dp[(k % 2)][n]); while (k > 0 && n > 0) { printf ("%d ", par[k][n]); n = par[k][n]; k--; } } /* 7 3 4 1 3 4 0 2 3 */

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

sequence.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sequence.cpp: In function 'int main()':
sequence.cpp:29:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d",&n, &k);
       ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &arr[i]);
             ~~~~~^~~~~~~~~~~~~~~
sequence.cpp: In function 'void solve(int, int, int, int, int)':
sequence.cpp:25:12: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
       solve(g,l,mid - 1, optl, opt);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...