답안 #708851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708851 2023-03-12T13:23:44 Z sofija6 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXR 100010
using namespace std;
ll pref[MAXR],a[MAXR];
ll Calc(ll L,ll R,ll pos)
{
    ll l=L,r=R,mid,p;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (a[mid]<=pos)
        {
            p=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p);
}
ll Check(ll x,ll n)
{
    ll ans=LLONG_MAX;
    for (ll i=1;i<=n-x+1;i++)
    {
        ll pos=(pref[i+x-1]-pref[i-1])/x;
        if (pos>=a[i])
            ans=min(ans,Calc(i,i+x-1,pos));
        if (pos+1<=a[i+x-1])
            ans=min(ans,Calc(i,i+x-1,pos+1));
    }
    return ans;
}
ll besthub(ll R,ll L,ll X[],ll B)
{
    for (ll i=0;i<R;i++)
    {
        pref[i+1]=pref[i]+X[i];
        a[i+1]=X[i];
    }
    ll l=1,r=R,mid,ans;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (Check(mid,R)<=B)
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'long long int Calc(long long int, long long int, long long int)':
ricehub.cpp:20:31: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p);
      |                         ~~~~~~^
ricehub.cpp: In function 'long long int besthub(long long int, long long int, long long int*, long long int)':
ricehub.cpp:54:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     return ans;
      |            ^~~
/usr/bin/ld: /tmp/cclOz50J.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status