답안 #781842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781842 2023-07-13T11:54:42 Z hariaakas646 쌀 창고 (IOI11_ricehub) C++17
0 / 100
1000 ms 724 KB
#include <bits/stdc++.h>
// #include <grader.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

int besthub(int r, int l, int X[], lli b)
{
    int lo = 0;
    int hi = r;
    vll vec(r);
    frange(i, r) vec[i] = X[i];
    vll pref(r);
    pref[0] = vec[0];
    forr(i, 1, r) pref[i] = pref[i - 1] + vec[i];

    while (lo != hi)
    {
        int mid = (hi + lo) / 2;
        bool check = false;

        forr(i, 0, r)
        {
            if (i - mid / 2 >= 0 && i + (mid - 1) / 2 < r)
            {
                int i1 = mid / 2;
                int i2 = (mid - 1) / 2;
                lli v = pref[i];
                if (i - i1 > 0)
                    v -= pref[i - i1 - 1];
                v = -v;
                v += vec[i] * (i1 + 1);
                v += pref[i + i2] - pref[i];
                v -= vec[i] * i2;
                if (v <= b)
                {
                    check = true;
                    break;
                }
            }
            if (i - (mid - 1) / 2 >= 0 && i + (mid) / 2 < r)
            {
                int i1 = (mid - 1) / 2;
                int i2 = (mid) / 2;
                lli v = pref[i];
                if (i - i1 > 0)
                    v -= pref[i - i1 - 1];
                v = -v;
                v += vec[i] * (i1 + 1);
                v += pref[i + i2] - pref[i];
                v -= vec[i] * i2;
                if (v <= b)
                {
                    check = true;
                    break;
                }
            }
        }
        if (check)
        {
            lo = mid;
        }
        else
            hi = mid - 1;
    }
    return lo;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1068 ms 724 KB Time limit exceeded
2 Halted 0 ms 0 KB -