Submission #486217

# Submission time Handle Problem Language Result Execution time Memory
486217 2021-11-11T02:11:36 Z Jomnoi Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ricehub.h>
#define DEBUG 0
using namespace std;
 
long long cost(int n, long long X[], long long mid, long long B) {
    deque <long long> L, R;
    for(int i = 0; i < n; i++) {
        if(X[i] <= mid) {
            L.push_front(mid - X[i]);
        }
        else {
            R.push_back(X[i] - mid);
        }
    }
    long long i = 0, j = 0;
    long long sum = 0;
    while(i < L.size() && j < R.size()) {
        if(L[i] <= R[j]) {
            sum += L[i++];
        }
        else {
            sum += R[j++];
        }
        if(sum > B) {
            return i + j - 1;
        }
    }
    while(i < L.size()) {
        sum += L[i++];
        if(sum > B) {
            return i + j - 1;
        }
    }
    while(j < R.size()) {
        sum += R[j++];
        if(sum > B) {
            return i + j - 1;
        }
    }
    return n;
}
 
int besthub(int R, long long L, long long X[], long long B) {
    long long l = 1, r = L, ans = 0, mid, cost1;
    long long l2, r2, mid2, pos2, cost2;
    while(l <= r) {
        mid = (l + r) / 2;
        cost1 = cost(R, X, mid, B);
        l2 = l + 1, r2 = r, pos2 = r;
        while(l2 <= r2) {
            mid2 = (l2 + r2) / 2;
            if(cost1 == cost(R, X, mid2, B)) {
                l2 = mid2 + 1;
            }
            else {
                r2 = mid2 - 1;
                pos2 = min(pos2, mid2);
            }
        }
        cost2 = cost(R, X, pos2, B);
        if(cost1 > cost2) {
            r = mid - 1;
            ans = max(ans, cost1);
        }
        else {
            l = mid + 1;
            ans = max(ans, cost2);
        }
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'long long int cost(int, long long int*, long long int, long long int)':
ricehub.cpp:18:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(i < L.size() && j < R.size()) {
      |           ~~^~~~~~~~~~
ricehub.cpp:18:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(i < L.size() && j < R.size()) {
      |                           ~~^~~~~~~~~~
ricehub.cpp:29:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     while(i < L.size()) {
      |           ~~^~~~~~~~~~
ricehub.cpp:35:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     while(j < R.size()) {
      |           ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccgQUQHV.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