답안 #1027679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027679 2024-07-19T08:59:54 Z vjudge1 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"



using namespace std;
const long long MAX=1e5+10;
long long pref[MAX];
vector<long long> niza;
long long budget;
bool can(long long x)
{
    for(long long i=0; i<=niza.size()-x; i++)
    {
        long long idx=(i+i+x)/2;
        long long pt=niza[idx];
        long long l=pt*(idx-i)-(pref[idx]-pref[i]+niza[i]-niza[idx]);
        long long r=(pref[i+x-1]-pref[idx]+niza[idx])-pt*(i+x-idx);
        //cout<<"for: "<<i+1<<" "<<i+x<<" lr is: "<<l<<" "<<r<<" "<<budget<<endl;
        if(l+r<=budget)return true;
    }
    return false;
}
long long besthub(long long R, long long L, long long X[], long long B)
{
    budget=B;
    for(long long i=0; i<R; i++)niza.push_back(X[i]);
    pref[0]=X[0];
    for(long long i=1; i<R; i++)pref[i]=pref[i-1]+X[i];
    long long b=0;
    long long e=R;
    long long res=0;
    while(b<=e)
    {
        long long mid=(b+e)/2;
        if(can(mid))
        {
            res=mid;
            b=mid+1;
        }
        else e=mid-1;
    }
    return res;
}
/*int main()
{
    int R,L,B;
    cin>>R>>L>>B;
    int X[R];
    budget=B;
    for(int i=0; i<R; i++)cin>>X[i];
    for(int i=0; i<R; i++)niza.push_back(X[i]);
    pref[0]=X[0];
    for(int i=1; i<R; i++)pref[i]=pref[i-1]+X[i];
    int b=0;
    int e=R;
    int res=0;
    while(b<=e)
    {
        int mid=(b+e)/2;
        cout<<"mid: "<<mid<<endl;
        if(can(mid))
        {
            res=mid;
            b=mid+1;
        }
        else e=mid-1;
    }
    cout<<res<<endl;
    return 0;
}
5 20 6
1 2 10 12 14*/

Compilation message

ricehub.cpp: In function 'bool can(long long int)':
ricehub.cpp:13:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   13 |     for(long long i=0; i<=niza.size()-x; i++)
      |                        ~^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccy4BIi0.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