답안 #1007137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007137 2024-06-24T12:14:26 Z The_Samurai 쌀 창고 (IOI11_ricehub) C++17
100 / 100
13 ms 4300 KB
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int besthub(int n, int L, int X[], long long B) {
    vector<ll> pref(n);
    for (int i = 0; i < n; i++) {
        pref[i] = (i > 0 ? pref[i - 1] : 0) + X[i];
    }
    auto sum = [&](int l, int r) -> ll {
        if (l > r) return 0;
        return pref[r] - (l > 0 ? pref[l - 1] : 0);
    };
    auto check = [&](int c) -> bool {
        for (int lx = 0, rx = c - 1; rx < n; lx++, rx++) {
            int mid = (lx + rx) >> 1;
            ll need = 1ll * X[mid] * (mid - lx) - sum(lx, mid - 1);
            need += sum(mid + 1, rx) - 1ll * X[mid] * (rx - mid);
            if (need <= B) return true;
        }
        return false;
    };
    int lx = 1, rx = n, best = 0;
    while (lx <= rx) {
        int mid = (lx + rx) >> 1;
        if (check(mid)) {
            best = mid;
            lx = mid + 1;
        } else {
            rx = mid - 1;
        }
    }
    return best;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 448 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 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 1 ms 484 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 456 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 8 ms 4032 KB Output is correct
4 Correct 9 ms 4180 KB Output is correct
5 Correct 5 ms 3416 KB Output is correct
6 Correct 4 ms 3164 KB Output is correct
7 Correct 11 ms 4188 KB Output is correct
8 Correct 7 ms 4208 KB Output is correct
9 Correct 4 ms 3164 KB Output is correct
10 Correct 4 ms 3164 KB Output is correct
11 Correct 12 ms 4188 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 5 ms 3420 KB Output is correct
14 Correct 5 ms 3420 KB Output is correct
15 Correct 10 ms 3864 KB Output is correct
16 Correct 7 ms 3932 KB Output is correct
17 Correct 7 ms 3932 KB Output is correct
18 Correct 8 ms 4300 KB Output is correct
19 Correct 13 ms 4188 KB Output is correct
20 Correct 11 ms 4184 KB Output is correct