답안 #1003252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003252 2024-06-20T08:15:04 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
    ll n = R, i, j, ans = 0;
    ll h[n+5], pref[n+5];
    ll l = 1, r = L;
    vl v;
    v.pb(0);
    pref[0] = 0;
    for(i = 1; i <= n; i++)
    {
        h[i] = X[i-1];
        pref[i] = pref[i-1] + h[i];
        v.pb(X[i-1]);
    }
    L = min(L, h[n]);
    for(ll mid = 0; mid <= L; mid++)
    {
        ll lb = lower_bound(all(v), mid) - v.begin();
        ll tl = lb - 1, tr = lb + 1, sum1 = 0, sum2 = 0;
        //cout << "mid: " << mid << " lb: " << lb << " sum1: ";
        while((tl >= 1 && tl <= n) || (tr >= 1 && tr <= n))
        {
            ll cost1 = LLONG_MAX, cost2 = LLONG_MAX;
            if(tl >= 1 && tl <= n)
                cost1 = mid - h[tl];
            if(tr >= 1 && tr <= n)
                cost2 = h[tr] - mid;
            //cout << "cost1: " << cost1 << " cost2: " << cost2 << "\n";
            if(cost1 == LLONG_MAX && cost2 == LLONG_MAX)
                break;
            if(cost1 <= cost2){
                sum1 += cost1;
                tl--;
            }
            else{
                sum2 += cost2;
                tr++;
            }
            if(sum1 + sum2 > B)
            {
                if(cost1 <= cost2){
                    sum1 -= cost1;
                    tl++;
                }
                else{
                    sum2 -= cost2;
                    tr--;
                }
                break;
            }
        }
        //cout << sum1 << " sum2: " << sum2 << "\n";
        tl++, tr--;
        ans = max(ans, (tr - tl + 1));
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:30:20: error: no matching function for call to 'min(int&, long long int&)'
   30 |     L = min(L, h[n]);
      |                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ricehub.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
ricehub.cpp:30:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   30 |     L = min(L, h[n]);
      |                    ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from ricehub.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
ricehub.cpp:30:20: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   30 |     L = min(L, h[n]);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ricehub.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
ricehub.cpp:30:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |     L = min(L, h[n]);
      |                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from ricehub.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
ricehub.cpp:30:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |     L = min(L, h[n]);
      |                    ^
ricehub.cpp:18:18: warning: unused variable 'j' [-Wunused-variable]
   18 |     ll n = R, i, j, ans = 0;
      |                  ^
ricehub.cpp:20:8: warning: unused variable 'l' [-Wunused-variable]
   20 |     ll l = 1, r = L;
      |        ^
ricehub.cpp:20:15: warning: unused variable 'r' [-Wunused-variable]
   20 |     ll l = 1, r = L;
      |               ^