답안 #1003202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003202 2024-06-20T07:45:51 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
0 / 100
97 ms 2264 KB
#include<bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
    ll n = R, i;
    ll h[n+5], pref[n+5];
    pref[0] = 0;
    vl v;
    v.pb(0);
    map<ll, ll>mp;
    for(i = 1; i <= n; i++){
        h[i] = X[i-1];
        v.pb(h[i]);
        mp[h[i]]++;
    }
    for(i = 1; i <= n; i++)
        pref[i] = pref[i-1] + h[i];
    ll res = 0;
    for(i = 1; i <= n; i++)
    {
        ll l = i, r = n, ans = i;
        //cout << "i: " << i << "\n";
        while(l <= r)
        {
            ll mid = (l + r) / 2;
            //cout << "mid: " << mid << " ok: ";
            ll tl = h[i], tr = h[mid], ok = LLONG_MAX;
            while(tl <= tr)
            {
                ll tmid = (tl + tr) / 2;
                ll lb = lower_bound(all(v), tmid) - v.begin();
                ll sum1 = tmid * (lb - i + 1) - (pref[lb] - pref[i-1]);
                ll sum2 = pref[mid] - pref[lb] - (mid - lb) * tmid;
                ll sum = sum1 + sum2;
                ok = min(ok, sum);
                if(sum1 > sum2)
                    tr = tmid - 1;
                else
                    tl = tmid + 1;
            }
            //cout << ok << "\n";
            if(ok <= B){
                l = mid + 1;
                ans = max(ans, mid);
            }
            else
                r = mid - 1;
        }
        res = max(res, ans - i + 1);
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 2264 KB Output is correct
2 Incorrect 89 ms 2264 KB Output isn't correct
3 Halted 0 ms 0 KB -