답안 #1039329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039329 2024-07-30T18:01:58 Z fimh 수열 (APIO14_sequence) C++14
0 / 100
4 ms 8540 KB
#include <bits/stdc++.h>
using ll = long long;
// #define int long long
#define fi first
#define pll pair<ll, ll>
#define se second
#define isz(x) (int)(x).size()
#define sq(x) (ll)(x)*(x)
using namespace std;

const ll inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 5;
const int block = 500;

int ps[maxn], trace[maxn][201];
ll dp[maxn][2];

void compute(int j, int l, int r, int optl, int optr){
    if (l > r) return;
    int mid = (l + r) >> 1;
    pll best = {inf, -1};
    for (int i = optl; i <= min(mid, optr); ++i){
        ll cost = sq(ps[mid] - ps[i - 1]);
        if (best.fi >= dp[i - 1][0] + cost){
            best.fi = dp[i - 1][0] + cost;
            best.se = i;
            trace[mid][j] = i;
        }
    }
    dp[mid][1] = best.fi;
    int opt = best.se;
    compute(j, l, mid - 1, optl, opt);
    compute(j, mid + 1, r, opt, optr);
}

void test(){
    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; ++i){
        cin >> ps[i]; ps[i] += ps[i - 1];
        dp[i][0] = sq(ps[i]);
    }
    for (int j = 2; j <= k + 1; ++j){
        compute(j, 1, n, 1, n);
        for (int i = 1; i <= n; ++i) dp[i][0] = dp[i][1];
    }
    ll ans = (sq(ps[n]) - dp[n][0]) / 2; cout << ans << "\n";
    vector<int> path;
    int y = k + 1, x = trace[n][y];
    while (y > 1){
        path.push_back(x - 1);
        x = trace[x - 1][y]; --y;
    }
    reverse(path.begin(), path.end());
    for (int i : path) cout << i << " ";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    test();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 460 KB declared answer doesn't correspond to the split scheme: declared = 108, real = 107
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB declared answer doesn't correspond to the split scheme: declared = 1093956, real = 1093726
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 2396 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 1 ms 2392 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Incorrect 1 ms 2392 KB declared answer doesn't correspond to the split scheme: declared = 1499437552673, real = 1452556400750
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB declared answer doesn't correspond to the split scheme: declared = 21503404, real = 21418568
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8540 KB declared answer doesn't correspond to the split scheme: declared = 1818678304, real = 1695400000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -