제출 #134968

#제출 시각아이디문제언어결과실행 시간메모리
134968wilwxk수열 (APIO14_sequence)C++14
50 / 100
2060 ms131076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+5; const ll INF=1e18; ll dp[MAXN][205]; int opt[MAXN][205]; ll soma[MAXN]; ll v[MAXN]; int n, x; int main() { scanf("%d %d", &n, &x); x++; for(int i=1; i<=n; i++) scanf("%lld", &v[i]); for(int i=1; i<=n; i++) soma[i]=soma[i-1], soma[i]+=v[i]; dp[0][0]=0; for(int i=1; i<=x; i++) dp[0][i]=-INF; for(int i=1; i<=n; i++) dp[i][0]=-INF; for(int i=1; i<=n; i++) { for(int j=1; j<=x; j++) { dp[i][j]=dp[i-1][j-1]+v[i]*soma[i-1]; opt[i][j]=i-1; for(int k=0; k<i; k++) { ll val=dp[k][j-1]+(soma[i]-soma[k])*soma[k]; if(val>=dp[i][j]) { dp[i][j]=val; opt[i][j]=k; } } // printf("%d %d >> %lld // %d\n", i, j, dp[i][j], opt[i][j]); } } printf("%lld\n", dp[n][x]); vector<int> respf; int ind=n; int k=x; while(respf.size()<x-1) { respf.push_back(opt[ind][k]); ind=opt[ind][k--]; } reverse(respf.begin(), respf.end()); for(auto cur : respf) printf("%d ", cur); }

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

sequence.cpp: In function 'int main()':
sequence.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(respf.size()<x-1) {
        ~~~~~~~~~~~~^~~~
sequence.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x); x++;
  ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:15:31: 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", &v[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...