제출 #855293

#제출 시각아이디문제언어결과실행 시간메모리
855293vjudge1수열 (APIO14_sequence)C++17
0 / 100
110 ms14592 KiB
#include<bits/stdc++.h> #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") using namespace std; #define int long long #define y1 cheza mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N=1100; const int B=700; const int M=1e7+10; const int mod=1e9+7; const int INF=1e9; const long double eps=1e-8; const int dx[]={1,-1,0,0}; const int dy[]={0,0,-1,1}; const int debug=0; int n,k; int a[N]; int dp[N][N]; int pr[N][N]; int pref[N]; void test(){ cin>>n>>k; for(int i=1;i<=n;i++){ cin>>a[i]; pref[i]=pref[i-1]+a[i]; } for(int kk=1;kk<=k+1;kk++){ for(int i=1;i<=n;i++){ for(int j=0;j<i;j++){ int y=dp[j][kk-1]+(pref[i]-pref[j])*(pref[n]-pref[i]); if(y>=dp[i][kk]){ dp[i][kk]=y; pr[i][kk]=j; } } } } // A B C // k1=AC+BC // k1=AB+BC // k1=AB+AC // k2=AC+BC+AB // k2=AB+AC+BC // for(int i=1;i<=k+1;i++){ // for(int j=1;j<=n;j++){ // cout<<dp[j][i]<<' '; // } // cout<<'\n'; // } // for(int i=1;i<=k+1;i++){ // for(int j=1;j<=n;j++){ // cout<<pr[j][i]<<' '; // } // cout<<'\n'; // } // return; int mx=dp[n][k+1]; int cur=pr[n][k+1]; vector<int>ans; ans.push_back(cur); while(pr[cur][k]){ cur=pr[cur][k]; k--; ans.push_back(cur); } cout<<mx<<'\n'; reverse(ans.begin(),ans.end()); for(auto i:ans){ cout<<i<<' '; } cout<<'\n'; } /* */ signed main(){ // cout<<"HEllo\n"; // freopen("INPUT.TXT","r",stdin); // freopen("OUTPUT.TXT","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); long long t2=1; // cin>>t2; // scanf("%lld",&t2); for(int i=1;i<=t2;i++){ // cout<<"Case "<<i<<": "; test(); } return 0; } /* temmie luck */
#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...