제출 #562993

#제출 시각아이디문제언어결과실행 시간메모리
562993penguin133수열 (APIO14_sequence)C++14
71 / 100
266 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define int long long pair<int, int> dp[205][100005]; int P[100005], A[100005],n,k; void dnc(int l, int r, int optl, int optr, int i){ if(l > r)return; int mid = (l + r)/2, maxx = -1e18, pos = optl; for(int j=optl;j<=min(optr, mid-1);j++){ int ans = dp[i-1][j].first + (P[mid] - P[j]) * (P[n] - P[mid]); if(ans > maxx)maxx = ans, pos = j; } dp[i][mid] = make_pair(maxx,pos); dnc(l,mid-1,optl,pos,i); dnc(mid+1,r,pos,optr,i); } main(){ ios::sync_with_stdio(0);cin.tie(0); cin >> n >> k; for(int i=1;i<=n;i++)cin >> A[i], P[i] = P[i-1] + A[i]; for(int i=1;i<=n;i++)dp[1][i].first = (P[n] - P[i])*P[i]; for(int i=2;i<=k;i++)dnc(1,n,1,n,i); int maxi = -1e18, in; for(int i=1;i<=n;i++)if(dp[k][i].first > maxi)maxi = dp[k][i].first, in = i; cout << maxi << '\n'; cout << in << " "; int p = dp[k][in].second; while(p)cout << p << " ", k--, p = dp[k][p].second; /* cout << "\n\n"; for(int i=1;i<=k;i++){ for(int j=i;j<=n;j++)cout << dp[i][j].first << " " << dp[i][j].second << " "; cout << '\n'; } */ }

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

sequence.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main(){
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:27:6: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |  int p = dp[k][in].second;
      |      ^
#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...