제출 #466051

#제출 시각아이디문제언어결과실행 시간메모리
466051blue비스킷 담기 (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++)
    {
        if(a[i] <= x+1)
            M = 0;
        else if(a[i] % 2 == x % 2)
            M = (a[i] - x);
        else
            M = (a[i] - x) - 1;

        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:54:13: error: 'M' was not declared in this scope
   54 |             M = 0;
      |             ^
biscuits.cpp:56:13: error: 'M' was not declared in this scope
   56 |             M = (a[i] - x);
      |             ^
biscuits.cpp:58:13: error: 'M' was not declared in this scope
   58 |             M = (a[i] - x) - 1;
      |             ^
biscuits.cpp:60:17: error: 'M' was not declared in this scope
   60 |         a[i] -= M;
      |                 ^