답안 #528851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528851 2022-02-21T15:21:01 Z aSSSd 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
    return l+rng()%(r-l+1);
}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define iii pair<ii,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define mt make_tuple
#define getbit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define endl '\n'
#define all(v) v.begin(), v.end()
#define gg exit(0);
#define int long long
const int N = 1e5 + 100;
int n;
int a[N];
long long b;
int len;
int xuoi[N], ngc[N];
int f[N], g[N];
bool check(int mid)
{
    long long cur = b;
    int ret =0;
    forinc(i,1,n)
    {
        if(i + mid - 1 > n) break;
        int med = (i+i+mid)/2;
        int lenn = mid/2;
        if(mid&1)
        {
            int trc=xuoi[med+lenn-1]-f[med-1]*lenn- xuoi[med-1];
            int sau=ngc[med-lenn+1]-g[med+1]*lenn- ngc[med+1];
            if  (trc + sau <= cur) return 1;
        }
        else
        {
            int trc = xuoi[med + lenn - 2] - f[med-1]*(lenn-1) - xuoi[med-1];
            int sau = ngc[med-lenn+1] - g[med+1]*lenn - ngc[med+1];
            if(trc + sau <= cur) return 1;
        }
    }
    return 0;
}
main()
{
    fasty;

    // freopen("dbz.inp", "r", stdin);
     //freopen("dbz.out", "w", stdout);
    cin >> n >> len >> b;
    forinc(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    forinc(i,1,n-1)
    {
        f[i] = f[i-1] + a[i+1] - a[i];
        xuoi[i] = xuoi[i-1] + f[i];
    }
    fordec(i,n,2)
    {
        g[i] = g[i+1] + a[i] - a[i-1];
        ngc[i] = ngc[i+1] + g[i];
    }
    int l=1;
    int res;
    int r = n;
    while(l <= r)
    {
        int mid = (l+r)/2;
        if(check(mid))
        {
            res = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    cout << res;
}


Compilation message

ricehub.cpp: In function 'bool check(long long int)':
ricehub.cpp:35:9: warning: unused variable 'ret' [-Wunused-variable]
   35 |     int ret =0;
      |         ^~~
ricehub.cpp: At global scope:
ricehub.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main()
      | ^~~~
/usr/bin/ld: /tmp/ccfZ2SLZ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSJwTsV.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccfZ2SLZ.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