답안 #1087505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087505 2024-09-12T18:56:49 Z Thunnus 수열 (APIO14_sequence) C++17
0 / 100
56 ms 8796 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
//#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
 
struct Line{
    int m, c, i;
    Line(i64 _m, i64 _c, int _i) : m(_m), c(_c), i(_i) {}
 
    inline int calc(int x){
        return m * x + c;
    } 
 
    inline long double x_int(Line &other){
        return (long double)(c - other.c) / (other.m - m);
    }
};
 
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] += a[i - 1];
    }
 
    vector<vector<i64>> dp(2, vector<i64>(n + 1));
    vvi from(n + 1, vi(k + 2));
    for(int j = 1; j <= k + 1; j++){
        deque<Line> dq;
        dq.emplace_front(0, 0, 0);
        for(int i = 1; i <= n; i++){
            int ps = a[n] - a[i];
            while(sz(dq) >= 2 && dq.back().calc(ps) <= dq[sz(dq) - 2].calc(ps)){
                dq.pop_back();
            }
 
            dp[1][i] = dq.back().calc(ps) + a[i] * ps;
            from[i][j] = dq.back().i;
            Line cur = {-a[i], dp[0][i], i};
            while(sz(dq) >= 2 && cur.x_int(dq[0]) >= dq[1].x_int(dq[0])){
                dq.pop_front();
            }
            dq.emplace_front(cur);
        }
        dp[0] = dp[1];
    }
 
    cout << dp[0][n] << "\n";
    vi ind;
    for(int i = k + 1, idx = n; i >= 1; i--){
		ind.emplace_back(idx);
        idx = from[idx][i];
    }
    for(int i = sz(ind) - 1; i >= 1; i--){
        cout << ind[i] << " ";
    }
    cout << "\n";
    return 0;
}
// dp[i][j] = max(dp[z - 1][j - 1] + (a[i] - a[z - 1]) * (a[n] - a[i]))
// dp[i][j] = max(-a[z - 1] * (a[n] - a[i]) + dp[z - 1][j - 1]) + a[i] * (a[n] - a[i])
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB contestant found the optimal answer: 108 == 108
2 Correct 0 ms 348 KB contestant found the optimal answer: 999 == 999
3 Correct 0 ms 348 KB contestant found the optimal answer: 0 == 0
4 Correct 0 ms 348 KB contestant found the optimal answer: 1542524 == 1542524
5 Incorrect 0 ms 348 KB declared answer doesn't correspond to the split scheme: declared = 205032704, real = 4500000000
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 0 ms 348 KB contestant found the optimal answer: 302460000 == 302460000
3 Incorrect 1 ms 348 KB Integer 0 violates the range [1, 49]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 0 ms 348 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 1 ms 604 KB Integer 0 violates the range [1, 199]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 1 ms 348 KB contestant found the optimal answer: 140412195 == 140412195
3 Incorrect 5 ms 1308 KB declared answer doesn't correspond to the split scheme: declared = 2075003102, real = 43198051651734
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 2 ms 1116 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Incorrect 56 ms 8796 KB declared answer doesn't correspond to the split scheme: declared = 575374972, real = 576975984488808
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 8520 KB declared answer doesn't correspond to the split scheme: declared = -1679059520, real = 19795776960
2 Halted 0 ms 0 KB -