제출 #563002

#제출 시각아이디문제언어결과실행 시간메모리
563002penguin133수열 (APIO14_sequence)C++14
71 / 100
537 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int dp[2][100005]; int pre[205][100005]; int P[100005], A[100005]; deque<pair<pair<int, int> , int> > dq; int f(pair<int, int> x, int y){ return x.first*y + x.second; } long double intersect(int a, int b, int c, int d){ return (long double)(d-b)/(a-c); } void ins(int m , int c, int in){ while(dq.size() > 1){ int s = dq.size(); if(intersect(dq.back().first.first, dq.back().first.second,m,c) <= intersect(dq[s-2].first.first, dq[s-2].first.second, m,c))dq.pop_back(); else break; } dq.push_back(make_pair(make_pair(m,c), in)); } pair<int, int> query(int x){ while(dq.size() > 1){ if(f(dq[0].first, x) < f(dq[1].first, x))dq.pop_front(); else break; } return {f(dq[0].first, x), dq[0].second}; } main(){ ios::sync_with_stdio(0);cin.tie(0); int n,k;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] = (P[n] - P[i])*P[i]; for(int i=2;i<=k;i++){ int tmp = i %2; for(int j=i;j<=n-(k-i)+1;j++){ ins(P[j-1] + P[n], -P[n] * P[j-1] + dp[1-tmp][j-1], j-1); pair<int,int>x = query(P[j]); dp[tmp][j] = x.first- P[j] * P[j]; pre[i][j] = x.second; } dq.clear(); } int maxi = -1e9, in; for(int i=1;i<=n;i++)if(dp[k%2][i] > maxi)maxi = dp[k%2][i], in = i; cout << maxi << '\n'; cout << in << " "; int p = pre[k][in]; while(p)cout << p << " ", k--, p = pre[k][p]; /* 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:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main(){
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:49:6: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |  int p = pre[k][in];
      |      ^
#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...