제출 #653195

#제출 시각아이디문제언어결과실행 시간메모리
653195HuyQuang_re_Zero수열 (APIO14_sequence)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define N 100001 #define db double using namespace std; long long n,k,f[N][202],t[N],sum,i,j,a[N],m,tr[N][202]; void truyvet(int i,int j) { if(j==1) return ; truyvet(tr[i][j],j-1); cout<<tr[i][j]<<" "; } int main() { freopen("ntu.inp","r",stdin); freopen("ntu.out","w",stdout); cin>>n>>m; m++; // f[0][0]=1; // memset(f,-1,sizeof(f)); for(i=1;i<=n;i++) { cin>>a[i]; t[i]=t[i-1]+a[i]; f[i][1]=0; for(j=2;j<=min(i,m);j++) { sum=0; for(k=i;k>=1;k--) { sum+=a[k]; if(f[i][j]<f[k-1][j-1]+t[k-1]*sum) { f[i][j]=f[k-1][j-1]+t[k-1]*sum; tr[i][j]=k-1; } // if(i==2 && j==2 && k==1) cerr<<sum<<" "<<t[k-1]<<'\n'; // if(i==5 && j==2 && f[i][j]==48) cerr<<k<<" "<<f[k-1][j-1]<<'\n'; } } } //cerr<<f[4][1]<<'\n'; cout<<f[n][m]<<'\n'; truyvet(n,m); }

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

sequence.cpp: In function 'int main()':
sequence.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("ntu.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("ntu.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...