답안 #661216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661216 2022-11-25T00:07:23 Z benjaminkleyn 쌀 창고 (IOI11_ricehub) C++17
17 / 100
62 ms 3308 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;

ll pref[100001], x[100000];

ll sum(int l, int r)
{
    return pref[r+1] - pref[l];
}

ll cost(int l, int r, int i)
{
    return sum(i + 1, r) + x[i] * (2 * i - l - r) - sum(l, i - 1);
}

ll find_min(int l, int r)
{
    int lo = l, hi = r - 1, mid;
    while (lo < hi)
    {
        mid = (lo + hi) / 2;
        if (cost(l, r, mid + 1) < cost(l, r, mid))
            lo = mid + 1;
        else
            hi = mid;
    }
    for (int i = lo + 1; i <= hi; i++)
        if (cost(l, r, i) < cost(l, r, lo))
            lo = i;
    return cost(l, r, lo);
}

ll calc(int R, int X[], int cnt)
{
    ll mn = LLONG_MAX;
    for (int l = 0, r = cnt - 1; r < R; l++, r++)
        mn = min(mn, find_min(l, r));
    return mn;
}

int besthub(int R, int L, int X[], ll B) 
{
    for (int i = 0; i < R; i++)
        x[i] = X[i], pref[i + 1] = pref[i] + X[i];

    int lo = 0, hi = R;
    while (lo < hi)
    {
        int mid = (lo + hi + 1) / 2;

        if (calc(R, X, mid) <= B)
            lo = mid;
        else hi = mid - 1;
    }

    return lo;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 708 KB Output is correct
2 Correct 21 ms 724 KB Output is correct
3 Correct 31 ms 3308 KB Output is correct
4 Correct 32 ms 3284 KB Output is correct
5 Correct 62 ms 1596 KB Output is correct
6 Correct 61 ms 1620 KB Output is correct
7 Correct 25 ms 2908 KB Output is correct
8 Incorrect 39 ms 2972 KB Output isn't correct
9 Halted 0 ms 0 KB -