제출 #731249

#제출 시각아이디문제언어결과실행 시간메모리
731249Baytoro수열 (APIO14_sequence)C++17
50 / 100
138 ms6996 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl "\n" #define ll long long #define int long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9+9,N=1e3+5; int n,m; int dp[N][205],par[N][205],a[N],pref[N]; void solve(){ int n,k;cin>>n>>k; dp[0][0]=0; for(int i=1;i<=n;i++){ cin>>a[i]; pref[i]=a[i]+pref[i-1]; } for(int j=1;j<=k+1;j++){ for(int i=1;i<=n;i++){ dp[i][j]=-INF; par[i][j]=1; for(int last=i;last>=1;last--){ if(dp[i][j]<dp[last-1][j-1]+(pref[i]-pref[last-1])*(pref[n]-pref[i])){ dp[i][j]=dp[last-1][j-1]+(pref[i]-pref[last-1])*(pref[n]-pref[i]); par[i][j]=last-1; } } if(par[i][j]==0) par[i][j]=1; } } cout<<dp[n][k+1]<<endl; vector<int> ans; int cur=n; for(int i=k;i>0;i--){ cur=par[cur][i+1]; ans.pb(cur); } reverse(all(ans)); for(auto it: ans) cout<<it<<' '; } main(){ //fopn("balancing"); ios; int T=1; //cin>>T; for(int i=1;i<=T;i++){ //cout<<"Case #"<<i<<": "; solve(); } }

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

sequence.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      | ^~~~
sequence.cpp: In function 'void fopn(std::string)':
sequence.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"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...