제출 #135198

#제출 시각아이디문제언어결과실행 시간메모리
135198pedro_sponchiado수열 (APIO14_sequence)C++17
50 / 100
422 ms131076 KiB
#include<bits/stdc++.h> using namespace std; const long long int INF=112345678912345678; const int maxn=10010; const int maxk=210; int n, d; int a[maxn]; long long int parc[maxn], parc_2[maxn]; long long int S_2[maxn][maxn]; //long long int S_2(int i, int j){ long long int dp[maxn][maxk]; int opt[maxn][maxk]; int main(){ scanf("%d %d", &n, &d); for(int i=1; i<=n; i++){ scanf("%d", &a[i]); parc[i]=parc[i-1]+a[i]; parc_2[i]=parc_2[i-1]+a[i]*a[i]; } for(int i=1; i<=n; i++){ for(int k=i; k<=n; k++){ S_2[i][k]= (parc[k]-parc[i-1])*(parc[k]-parc[i-1])-parc_2[k]+parc_2[i-1]; } } for(int i=1; i<=n; i++) dp[i][0]=S_2[1][i]; for(int k=1; k<=d; k++){ for(int i=1; i<=n; i++){ dp[i][k]=INF; if(k>=i)continue; for(int l=1; l<i; l++){ if(dp[i][k]>dp[l][k-1]+S_2[l+1][i]){ dp[i][k]=dp[l][k-1]+S_2[l+1][i]; opt[i][k]=l; } } // printf("dp[%d][%d]=%lld\n", i, k, dp[i][k]); } } printf("%lld\n", (S_2[1][n]-dp[n][d])/2); int at=n; vector<int> aux; for(int i=d; i>=1; i--){ aux.push_back(opt[at][i]); at=opt[at][i]; } for(int i=d-1; i>=0; i--) printf("%d ", aux[i]); return 0; }

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

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