Submission #769734

#TimeUsernameProblemLanguageResultExecution timeMemory
769734boris_mihovPacking Biscuits (IOI20_biscuits)C++17
0 / 100
1 ms596 KiB
#include "biscuits.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 64;
const int INF = 1e9;

int n;
llong x;
llong a[MAXN];

llong rec(int pos, llong prenos)
{
    if (pos == n)
    {
        return 1;
    }

    llong ans = 0;
    llong curr = a[pos] + prenos;
    if (curr >= x) ans += rec(pos + 1, (curr - x) / 2);
    ans += rec(pos + 1, curr / 2);
    return ans;
}

bool check(int pos, int y, llong prenos)
{
    if (pos == n)
    {
        return 1;
    }

    llong ans = 0;
    llong curr = a[pos] + prenos;
    if (y & (1 << pos))
    {
        if (curr < x) return 0;
        return check(pos + 1, y, (curr - x) / 2);
    }

    return check(pos + 1, y, curr / 2);
}

llong count_tastiness(llong X, std::vector <llong> A)
{
    n = A.size();
    x = X;

    llong sum = 0;
    for (int i = 0 ; i < n ; ++i)
    {
        a[i] = A[i];
        sum += a[i] * (1LL << a[i]);
    }

    for (int y = 0 ; y <= sum ; ++y)
    {
        check(0, 0, y);
    }

    assert(sum <= 10000);
	return rec(0, 0);
}

Compilation message (stderr)

biscuits.cpp: In function 'bool check(int, int, llong)':
biscuits.cpp:37:11: warning: unused variable 'ans' [-Wunused-variable]
   37 |     llong ans = 0;
      |           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...