제출 #569012

#제출 시각아이디문제언어결과실행 시간메모리
569012Ronin13수열 (APIO14_sequence)C++14
39 / 100
2073 ms131072 KiB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

ll dp[100001][201];
ll p[100001][201];

const ll linf = 1e18 + 1;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int k; cin >> k;
    ll pref[n + 1];
    ll a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= k; j++) dp[i][j] = -linf;
    }
    dp[0][0] = 0;
    pref[0] = 0;
    for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < k; j++){
            for(int l = 0; l < i; l++){
                ll val = dp[l][j] + (pref[i] - pref[l]) * (pref[n] - pref[i]);
                if(dp[i][j + 1] < val){
                    dp[i][j + 1] = val;
                    p[i][j + 1] = l;
                }
            }
        }
    }
    ll ans = -1;
    ll mxi;
    for(int i = 1; i <= n; i++){
        if(ans < dp[i][k]) ans = dp[i][k], mxi = i;
    }
    cout << ans << "\n";
    int cnt = k;
    vector <int> vec;
    while(cnt){
        vec.pb(mxi);
        mxi = p[mxi][cnt];
        cnt--;
    }
    reverse(vec.begin(), vec.end());
    for(auto to : vec) cout << to << ' ';
    return 0;
}

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

sequence.cpp: In function 'int main()':
sequence.cpp:53:15: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |         vec.pb(mxi);
      |         ~~~~~~^~~~~
#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...