답안 #416449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416449 2021-06-02T11:59:54 Z Aldas25 Feast (NOI19_feast) C++14
41 / 100
30 ms 5824 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 200100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 1e13;
const ld PI = asin(1) * 2;
const ld EPS = 1e-6;

ll n, k;
ll a[MAXN];
ll pref[MAXN];
ll dp[MAXN];
ll cnt[MAXN];

void calc (ll lambda) {
    //cout << fixed << setprecision(3) << "    lambda = " << lambda << endl;
    int bg = 0;
    FOR(i, 1, n) {
        if (dp[bg] + pref[i] - pref[bg] - lambda > dp[i-1]) {
            dp[i] = dp[bg] + pref[i] - pref[bg] - lambda;
            cnt[i] = cnt[bg]+1;
        } else {
            dp[i] = dp[i-1];
            cnt[i] = cnt[i-1];
        }

        if (dp[bg] - pref[bg] < dp[i] - pref[i]) {
            bg = i;
        }

       // cout << fixed << setprecision(2) << " i = " << i << " dp = " << dp[i] << " pref = " << pref[i] << "  bg = " << bg << " cnt = " << cnt[i] << endl;
    }
}

int main()
{
    FAST_IO;

    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) pref[i] = pref[i-1] + a[i];

    ll le = 0, ri = INF;
    while (le < ri) {
        ll mid = (le+ri)/2;
        calc (mid);
        if (cnt[n] <= k) ri = mid;
        else le = mid+1;
    }

    calc (le);
    //ll ans = (ll)(round(dp[n] + cnt[n]*le));
    ll ans = dp[n] + cnt[n]*le;
    cout << ans << "\n";

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 5700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 2832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 5824 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 5700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -