답안 #134909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134909 2019-07-23T12:06:06 Z fredbr 수열 (APIO14_sequence) C++17
28 / 100
432 ms 3832 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int const maxn = 1010;
int const maxk = 210;
ll const inf = 0x3f3f3f3f3f3f3f3f;

ll p[maxn];
ll dp[maxk][maxn], opt[maxk][maxn];

ll solve(int k, int n) {
    if (dp[k][n] >= 0) return dp[k][n];
    
    if (k == 0) return 0;
    if (n == 1) return -inf;

    ll& d = dp[k][n];
    ll& op = opt[k][n];

    d = 0, op = 0;;

    for (int i = 1; i < n; i++) {
        ll cost = p[i] * (p[n]-p[i]) + solve(k-1, i);
        
        if (cost > d) {
            op = i;
            d = cost;
        }
    }

    return d;
}

vector<ll> recover(int k, int n) {
    vector<ll> res;

    while (k != 0) {
        res.push_back(opt[k][n]);
        n = opt[k][n];
        k--;
    }

    reverse(res.begin(), res.end());

    return res;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    
    memset(dp, -1, sizeof(dp));

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        p[i] += p[i-1];
    }

    ll ans = solve(k, n);

    auto res = recover(k, n);

    cout << ans << "\n";

    for (ll i : res) cout << i << " ";
    cout << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2040 KB contestant found the optimal answer: 108 == 108
2 Correct 3 ms 2040 KB contestant found the optimal answer: 999 == 999
3 Incorrect 3 ms 2040 KB Integer 0 violates the range [1, 1]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2168 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 4 ms 2040 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 4 ms 2168 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 3 ms 2040 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 3 ms 2040 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 4 ms 2040 KB contestant found the optimal answer: 933702 == 933702
7 Correct 4 ms 2168 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 4 ms 2168 KB contestant found the optimal answer: 687136 == 687136
9 Correct 3 ms 2040 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 4 ms 2040 KB contestant found the optimal answer: 29000419931 == 29000419931
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2040 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 4 ms 2040 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 9 ms 2936 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 3 ms 2040 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 9 ms 2680 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 9 ms 2808 KB Integer 0 violates the range [1, 199]
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2040 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 7 ms 2168 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 260 ms 3696 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 7 ms 2040 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 432 ms 3648 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 357 ms 3500 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 261 ms 3660 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 264 ms 3704 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 80 ms 2296 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 159 ms 2808 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -