답안 #1110896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110896 2024-11-10T23:25:38 Z DylanSmith Feast (NOI19_feast) C++17
100 / 100
112 ms 4608 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)

mt19937 rng;

pair<ll, int> check(vector<int> &a, ll cost) {
    pair<ll, int> n = {0, 0}, y = {LLONG_MIN, 0};
    for (int i = 0; i < sz(a); i++) {
        pair<ll, int> n2 = n;
        if (y.first != LLONG_MIN) n2 = max(n2, y);
        pair<ll, int> y2 = {n.first + a[i] - cost, n.second + 1};
        if (y.first != LLONG_MIN) {
            y2 = max(y2, {y.first + a[i], y.second});
            y2 = max(y2, {y.first + a[i] - cost, y.second + 1});
        }
        swap(n, n2);
        swap(y, y2);
    }
    auto res = max(n, y);
    if (cost == 0) res.second = sz(a);
    return res;
}

ll search(vector<int> &a, int K, ll l, ll r) {
    if (l > r) return LLONG_MIN;
    ll mid = (l + r) / 2;
    auto p = check(a, mid);
    if (p.second >= K) {
        ll m = search(a, K, mid + 1, r);
        if (m != LLONG_MIN) return m;
        return p.first + K * mid;
    }
    return search(a, K, l, mid - 1);
}

void solve() {
    int N, K; cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < a.size(); i++) cin >> a[i];
    cout << search(a, K, 0, LLONG_MAX / 2) << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    solve();

    return 0;
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 0; i < a.size(); i++) cin >> a[i];
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1360 KB Output is correct
2 Correct 68 ms 1360 KB Output is correct
3 Correct 82 ms 1616 KB Output is correct
4 Correct 67 ms 1616 KB Output is correct
5 Correct 66 ms 1616 KB Output is correct
6 Correct 67 ms 1528 KB Output is correct
7 Correct 64 ms 1360 KB Output is correct
8 Correct 66 ms 1616 KB Output is correct
9 Correct 66 ms 1360 KB Output is correct
10 Correct 74 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 1360 KB Output is correct
2 Correct 66 ms 1616 KB Output is correct
3 Correct 55 ms 1360 KB Output is correct
4 Correct 60 ms 1360 KB Output is correct
5 Correct 65 ms 1360 KB Output is correct
6 Correct 57 ms 1360 KB Output is correct
7 Correct 66 ms 1616 KB Output is correct
8 Correct 65 ms 1616 KB Output is correct
9 Correct 89 ms 1360 KB Output is correct
10 Correct 58 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 1616 KB Output is correct
2 Correct 82 ms 1360 KB Output is correct
3 Correct 83 ms 1616 KB Output is correct
4 Correct 81 ms 1360 KB Output is correct
5 Correct 83 ms 1616 KB Output is correct
6 Correct 83 ms 1784 KB Output is correct
7 Correct 83 ms 1616 KB Output is correct
8 Correct 81 ms 1616 KB Output is correct
9 Correct 83 ms 1616 KB Output is correct
10 Correct 83 ms 1788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 508 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1360 KB Output is correct
2 Correct 68 ms 1360 KB Output is correct
3 Correct 82 ms 1616 KB Output is correct
4 Correct 67 ms 1616 KB Output is correct
5 Correct 66 ms 1616 KB Output is correct
6 Correct 67 ms 1528 KB Output is correct
7 Correct 64 ms 1360 KB Output is correct
8 Correct 66 ms 1616 KB Output is correct
9 Correct 66 ms 1360 KB Output is correct
10 Correct 74 ms 1360 KB Output is correct
11 Correct 56 ms 1360 KB Output is correct
12 Correct 66 ms 1616 KB Output is correct
13 Correct 55 ms 1360 KB Output is correct
14 Correct 60 ms 1360 KB Output is correct
15 Correct 65 ms 1360 KB Output is correct
16 Correct 57 ms 1360 KB Output is correct
17 Correct 66 ms 1616 KB Output is correct
18 Correct 65 ms 1616 KB Output is correct
19 Correct 89 ms 1360 KB Output is correct
20 Correct 58 ms 1616 KB Output is correct
21 Correct 81 ms 1616 KB Output is correct
22 Correct 82 ms 1360 KB Output is correct
23 Correct 83 ms 1616 KB Output is correct
24 Correct 81 ms 1360 KB Output is correct
25 Correct 83 ms 1616 KB Output is correct
26 Correct 83 ms 1784 KB Output is correct
27 Correct 83 ms 1616 KB Output is correct
28 Correct 81 ms 1616 KB Output is correct
29 Correct 83 ms 1616 KB Output is correct
30 Correct 83 ms 1788 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 504 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 504 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 464 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 2 ms 336 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 2 ms 508 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 336 KB Output is correct
61 Correct 106 ms 4432 KB Output is correct
62 Correct 106 ms 4560 KB Output is correct
63 Correct 93 ms 4424 KB Output is correct
64 Correct 108 ms 4432 KB Output is correct
65 Correct 112 ms 4428 KB Output is correct
66 Correct 111 ms 4608 KB Output is correct
67 Correct 112 ms 4432 KB Output is correct
68 Correct 87 ms 4432 KB Output is correct
69 Correct 85 ms 4396 KB Output is correct
70 Correct 84 ms 4424 KB Output is correct