답안 #530803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530803 2022-02-26T20:47:26 Z SlavicG 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()


int query(int l, int r, vector<ll>& p) {
    return p[r] - (l ? p[l - 1] : 0);
}

bool ok(int val, vector<int>& x, ll b) {
    int n = sz(x);
    vector<ll> p(n);
    for(int i = 0;i < n; ++i) {
        p[i] = (i ? p[i - 1] : 0) + x[i];
    }

    for(int i = 0; i + val - 1 < n; ++i) {
        ll med = (i + val / 2);
        ll calc = x[med] * (i + val / 2 - i + 1) - query(i, i + val / 2, p);
        calc += query(i + val / 2, i + val - 1, p) - x[med] * (i + val - 1 - i - val / 2 + 1);
        if(calc <= b) return true;
    }
    return false;
}

int besthub(int R, int L, vector<int> x, ll b) {
    int l = 1, r = R, ans = 0;

    while(l <= r) {
        int mid = l + r >> 1;
        if(ok(mid, x, b)) {
            ans = mid;
            l = mid + 1;
        } else r = mid - 1;
    }

    return ans;
}

/*
void solve() {
    int r, l; ll b;
    cin >> r >> l >> b;
    vector<int> x(r);
    forn(i, r) cin >> x[i];

    cout << besthub(r, l, x, b) << "\n";
} 
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, std::vector<int>, long long int)':
ricehub.cpp:38:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         int mid = l + r >> 1;
      |                   ~~^~~
/usr/bin/ld: /tmp/ccNHzxcj.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