답안 #381776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381776 2021-03-25T23:17:02 Z jlallas384 수열 (APIO14_sequence) C++17
0 / 100
181 ms 6380 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[1005][205];
ll pref[1005];
int par[1005][205];

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto &x: a){
        cin >> x;
    }
    for(int i = 0; i < n; i++){
        pref[i+1] = pref[i] + a[i];
    }
    ll sm = accumulate(a.begin(),a.end(),0);
    int mx = 0,id = 0;
    for(int i = 1; i <= n; i++){
        sm -= a[i-1];
        for(int j = 1; j <= k; j++){
            for(int l = 0; l < i; l++){
                ll res = dp[l][j-1] + (pref[i] - pref[l]) * sm;
                if(res > dp[i][j]){
                    dp[i][j] = res;
                    par[i][j] = l;
                }
            }
        }
        if(dp[i][k] > mx){
            mx = dp[i][k];
            id = i;
        }
    }
    cout << dp[id][k] << "\n";
    vector<int> res;
    while(id != 0){
        res.push_back(id);
        id = par[id][k--];
    }
    reverse(res.begin(), res.end());
    for(int x: res){
        cout << x << " ";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB contestant found the optimal answer: 108 == 108
2 Correct 1 ms 384 KB contestant found the optimal answer: 999 == 999
3 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 492 KB contestant found the optimal answer: 302460000 == 302460000
3 Incorrect 1 ms 492 KB Integer 50 violates the range [1, 49]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 876 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 8 ms 876 KB Integer 200 violates the range [1, 199]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2796 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 6 ms 2796 KB contestant found the optimal answer: 140412195 == 140412195
3 Incorrect 181 ms 2796 KB Integer 1000 violates the range [1, 999]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 5612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 6380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -