답안 #285205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285205 2020-08-28T11:49:36 Z davooddkareshki 수열 (APIO14_sequence) C++17
0 / 100
1531 ms 33720 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define pii pair<int,int>
#define mpr make_pair

typedef long long ll;

const int maxn = 1e4+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;

int n, K;
int dp[maxn][210], up[maxn][210];
int ps[maxn], a[maxn];

void upd(int i, int k, int j)
{
    if(j < 0 || j >= i) return;

    int sum = ps[i]-ps[j];
    int val = dp[j][k-1] + sum*(sum-1)/2;
    if(val < dp[i][k])
    {
        dp[i][k] = val;
        up[i][k] = j;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

    dp[0][0] = 0;
    for(int k = 1; k <= K; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            dp[i][k] = inf;
            int hi = i, lo = 0;
            while(hi-lo > 1)
            {
                int tm = (hi + lo) >> 1;
                if(ps[i] - ps[tm] >= ps[i]/k) lo = tm;
                else                          hi = tm;
            }
            /// ps[i] - ps[lo] >= ps[i] / k
            for(int j = 0; j < i; j++) upd(i,k,j);
         /*   upd(i,k,lo-2);
            upd(i,k,lo-1);
            upd(i,k,lo);
            upd(i,k,lo+1);
            upd(i,k,lo+2);
        */
        }
    }

    ll ans = ps[n] * (ps[n] - 1) / 2;
    ans -= dp[n][K] * (dp[n][K]-1) / 2;

    int i = n, k = K;
    vector<int> out;
    while(k)
    {
        out.push_back(up[i][k]);
        i = up[i][k];
        k--;
    }

    cout<< ans <<"\n";
    for(auto x : out) cout<< x <<" ";
}

/*
7 3
4 1 3 4 0 2 3
*/



# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB declared answer doesn't correspond to the split scheme: declared = 91, real = 66
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 512 KB declared answer doesn't correspond to the split scheme: declared = -1249750536351680, real = 1090726
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1024 KB declared answer doesn't correspond to the split scheme: declared = -19995999285847872, real = 610590000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 3712 KB declared answer doesn't correspond to the split scheme: declared = -1249750015318396, real = 20154026
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1531 ms 33444 KB declared answer doesn't correspond to the split scheme: declared = -19995997658088330, real = 1496550000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 397 ms 33720 KB position 2 occurs twice in split scheme
2 Halted 0 ms 0 KB -