답안 #1003253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003253 2024-06-20T08:15:27 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
0 / 100
26 ms 1116 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, j, ans = 0;
    ll h[n+5], pref[n+5];
    ll l = 1, r = L;
    vl v;
    v.pb(0);
    pref[0] = 0;
    for(i = 1; i <= n; i++)
    {
        h[i] = X[i-1];
        pref[i] = pref[i-1] + h[i];
        v.pb(X[i-1]);
    }
    L = min(L, (int)h[n]);
    for(ll mid = 0; mid <= L; mid++)
    {
        ll lb = lower_bound(all(v), mid) - v.begin();
        ll tl = lb - 1, tr = lb + 1, sum1 = 0, sum2 = 0;
        //cout << "mid: " << mid << " lb: " << lb << " sum1: ";
        while((tl >= 1 && tl <= n) || (tr >= 1 && tr <= n))
        {
            ll cost1 = LLONG_MAX, cost2 = LLONG_MAX;
            if(tl >= 1 && tl <= n)
                cost1 = mid - h[tl];
            if(tr >= 1 && tr <= n)
                cost2 = h[tr] - mid;
            //cout << "cost1: " << cost1 << " cost2: " << cost2 << "\n";
            if(cost1 == LLONG_MAX && cost2 == LLONG_MAX)
                break;
            if(cost1 <= cost2){
                sum1 += cost1;
                tl--;
            }
            else{
                sum2 += cost2;
                tr++;
            }
            if(sum1 + sum2 > B)
            {
                if(cost1 <= cost2){
                    sum1 -= cost1;
                    tl++;
                }
                else{
                    sum2 -= cost2;
                    tr--;
                }
                break;
            }
        }
        //cout << sum1 << " sum2: " << sum2 << "\n";
        tl++, tr--;
        ans = max(ans, (tr - tl + 1));
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:18:18: warning: unused variable 'j' [-Wunused-variable]
   18 |     ll n = R, i, j, ans = 0;
      |                  ^
ricehub.cpp:20:8: warning: unused variable 'l' [-Wunused-variable]
   20 |     ll l = 1, r = L;
      |        ^
ricehub.cpp:20:15: warning: unused variable 'r' [-Wunused-variable]
   20 |     ll l = 1, r = L;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 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 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1116 KB Output is correct
2 Incorrect 23 ms 1116 KB Output isn't correct
3 Halted 0 ms 0 KB -