제출 #982560

#제출 시각아이디문제언어결과실행 시간메모리
982560Error404수열 (APIO14_sequence)C++17
50 / 100
2049 ms24352 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back


int main(){
    int n,parts;
    cin >> n >> parts;
    ll a[n+1], pref[n+1];
    
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
   
    pref[0]=0;
    
    for(int i = 1; i <= n; i++){
        pref[i]= pref[i-1]+a[i];
    }
    
    
    ll dp[n+1][parts+1];
    int p[n+1][parts+1];
    memset(dp,0,sizeof(dp));
    memset(p,0,sizeof(p));
    
    
    for(int i = 1; i <=n; i++){
        for(int j = 1; j <= parts;j++){
            for(int k = i; k >=1;k--){
                ll val = dp[k-1][j-1] + (pref[i]-pref[k-1]) * (pref[n]-pref[i]);
                if(dp[i][j] < val){
                    dp[i][j] = val;
                    p[i][j] = k-1;
                }
                
            }
        }
    }
    
    
    
    ll pos = 1;
    for(int i = 1; i <= n; i++){
        if(dp[i][parts]> dp[pos][parts]) pos= i;
    }
    cout << dp[pos][parts]<< endl;
   vector<int>ans;
    int num = parts;
    while(true){
        ans.pb(pos);
        pos= p[pos][parts];
        parts--;
        if(!pos || parts==0)break;
    }
    reverse(ans.begin(),ans.end());
    for(int i : ans){
        cout << i << " ";
    }
}

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

sequence.cpp: In function 'int main()':
sequence.cpp:52:9: warning: unused variable 'num' [-Wunused-variable]
   52 |     int num = parts;
      |         ^~~
#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...