답안 #1025702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025702 2024-07-17T08:55:38 Z Gr1sen Feast (NOI19_feast) C++17
59 / 100
1000 ms 101204 KB
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define pi pair<ll, ll>
#define ppi pair<ll, pi>
#define vp vector<ppi>
#define vvp vector<vp>
#define pn pair<node, node>
#define vpn vector<pn>

ll n, k;
vi L;

struct node {
    ll v = -1, tv = -1, sa = -1;
};

node maks(node a, node b) {
    if (a.v >= b.v) return a;
    return b;
}

vpn M;


node oink(ll c, ll p = 0, bool q = 0) {
    if (p == n) return {0, 0, 0};
    if (q) {
        if (M[p].first.v != -1) return M[p].first;
        if (L[p] >= 0) {
            node a = oink(c, p+1, 1);
            a.v += L[p];
            a.tv += L[p];
            return M[p].first = a;
        }
        node a = oink(c, p+1, 1);
        a.v += L[p];
        a.tv += L[p];
        node b = oink(c, p+1, 0);
        return M[p].first = maks(a, b);
    }
    if (M[p].second.v != -1) return M[p].second;
    node a = oink(c, p+1, 1);
    a.v += L[p] - c;
    a.tv += L[p];
    a.sa++;
    node b = oink(c, p+1, 0);
    return M[p].second = maks(a, b);
}

/*
*/

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    L = vi(n);
    for (auto &i : L) cin >> i;

    ll l = 0, r = 1000000000000;
    ll ans;
    while (l < r) {
        //cerr << l << " " << r << endl;
        M = vpn(n, pn({-1, -1, -1}, {-1, -1, -1}));
        ll m = (l+r)/2;
        node a = oink(m);
        if (a.sa == k) {
            ans = a.tv;
            break;
        }
        if (a.sa > k) {
            l = m+1;
            continue;
        }
        //ans = a.tv;
        r = m;
    }
    cout << ans << "\n";
}

/*
6 1
1 -2 3 -1 5 -6

6 2
1 2 3 -10 5 6

6 4
-1 -2 -1 0 -5 -1
*/
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1051 ms 98260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1018 ms 98896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 100272 KB Output is correct
2 Correct 188 ms 98956 KB Output is correct
3 Correct 162 ms 99920 KB Output is correct
4 Correct 170 ms 98992 KB Output is correct
5 Correct 172 ms 99924 KB Output is correct
6 Correct 192 ms 100556 KB Output is correct
7 Correct 271 ms 100896 KB Output is correct
8 Correct 211 ms 99976 KB Output is correct
9 Correct 138 ms 101204 KB Output is correct
10 Correct 221 ms 100856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1044 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1051 ms 98260 KB Time limit exceeded
2 Halted 0 ms 0 KB -