제출 #1032720

#제출 시각아이디문제언어결과실행 시간메모리
1032720vannnnnnnn수열 (APIO14_sequence)C++14
50 / 100
2087 ms32092 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std; ll n, k, pre[10005], a[10005]; pair<ll, ll>dp[205][10005]; int main() { ll n, k; scanf("%lld %lld", &n, &k); for(int i=1; i<=n; i++) { scanf("%lld", &a[i]); pre[i]=pre[i-1]+a[i]; } for(int i=0; i<=k; i++)for(int j=0; j<=n; j++)dp[i][j].fi=-1e9; dp[0][0].fi=0;dp[0][0].se=0; for(int i=1; i<=k; i++) { for(int l=0; l<n-1; l++) { for(int r=l+1; r<n; r++) { if(dp[i][r].fi<dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]) && dp[i-1][l].fi!=-1e9) { dp[i][r].fi=dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]); dp[i][r].se=l; // printf("%lld %lld %d %d %d\n", dp[i][r].fi, dp[i][r].se, i, r, l); } } } } ll ans=-1, idx; for(int i=1; i<=n; i++) { if(ans<dp[k][i].fi) { ans=dp[k][i].fi; idx=i; } } printf("%lld\n", ans); vector<ll>res; while(k>0) { res.push_back(idx); idx=dp[k][idx].se; k--; } reverse(res.begin(), res.end()); for(auto x:res)printf("%lld ", x); printf("\n"); } /* 7 3 4 1 3 4 0 2 3 */

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

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