답안 #1110891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110891 2024-11-10T23:00:59 Z DylanSmith Feast (NOI19_feast) C++17
18 / 100
74 ms 4680 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});
        swap(n, n2);
        swap(y, y2);
    }
    return max(n, y);
}

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 + p.second * mid + mid * (K - p.second);
    }
    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];
    ll res = search(a, K, 1, LLONG_MAX / 2);
    if (res == LLONG_MIN) cout << "0\n";
    else cout << res << "\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:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 0; i < a.size(); i++) cin >> a[i];
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2640 KB Output is correct
2 Correct 38 ms 2640 KB Output is correct
3 Correct 38 ms 2488 KB Output is correct
4 Incorrect 40 ms 2640 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4432 KB Output is correct
2 Correct 65 ms 4400 KB Output is correct
3 Correct 65 ms 4424 KB Output is correct
4 Correct 64 ms 4432 KB Output is correct
5 Correct 65 ms 4544 KB Output is correct
6 Correct 65 ms 4548 KB Output is correct
7 Correct 65 ms 4428 KB Output is correct
8 Correct 68 ms 4432 KB Output is correct
9 Correct 67 ms 4424 KB Output is correct
10 Correct 74 ms 4680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -