제출 #466041

#제출 시각아이디문제언어결과실행 시간메모리
466041blue비스킷 담기 (IOI20_biscuits)C++17
컴파일 에러
0 ms0 KiB
#include "biscuits.h"
#include <vector>
using namespace std;

//x = number of people (p)
//y = tastiness of each bag (i)

long long x;

void tle_assert(bool b)
{
    if(!b) while(1);
}

long long solve(vector<int> B)
{
    if(B.empty()) return 1;

    //Case 1
    long long ans1 = 1;
    for(int i = 0; i < (int)B.size(); i++)
        ans1 *= 2;

    //Case 2
    long long ans2;
    int pos2 = -1;
    for(int i = (int)B.size() - 1; i >= 0; i--)
        if(B[i] == 2)
        {
            pos2 = i;
            break;
        }
    if(pos2 == -1)
        ans2 = 0;
    else
    {
        B.resize(pos2);
        ans2 = solve(B);
    }

    return ans1 + ans2;
}

long long count_tastiness(long long x1, vector<long long> a)
{
    x = x1;

    while((int)a.size() < 62) a.push_back(0);
	int k = (int)a.size();

    for(int i = 0; i+1 < k; i++)
    {
        long long M = max(0, 2*(a[i] - (x+1))/2);
        a[i] -= M;
        a[i+1] += M/2;
    }

    vector<int> B;

    long long res = 1;
    for(int i = 0; i < k; i++)
    {
        if(a[i] == 0)
        {
            res *= solve(B);
            B.clear();
        }
        else
            B.push_back(a[i]);
    }

    return res;
}

컴파일 시 표준 에러 (stderr) 메시지

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:53:48: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   53 |         long long M = max(0, 2*(a[i] - (x+1))/2);
      |                                                ^
In file included from /usr/include/c++/10/vector:60,
                 from biscuits.h:1,
                 from biscuits.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
biscuits.cpp:53:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   53 |         long long M = max(0, 2*(a[i] - (x+1))/2);
      |                                                ^
In file included from /usr/include/c++/10/vector:60,
                 from biscuits.h:1,
                 from biscuits.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
biscuits.cpp:53:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   53 |         long long M = max(0, 2*(a[i] - (x+1))/2);
      |                                                ^