Submission #789439

#TimeUsernameProblemLanguageResultExecution timeMemory
789439borisAngelovPacking Biscuits (IOI20_biscuits)C++17
0 / 100
1084 ms340 KiB
#include "biscuits.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

using namespace std;

long long count_tastiness(long long x, vector<long long> a)
{
    int sum = 0;

    for (int i = 0; i < a.size(); ++i)
    {
        sum += a[i] * (1LL << i);
    }

    int bits = 60;
    int up_to = sum / x;
    int ans = 0;

    for (int i = 0; i <= up_to; ++i)
    {
        vector<int> cnt(20, 0);

        for (int j = 0; j <= 16; ++j)
        {
            if (j < a.size())
            {
                cnt[j] = a[j];
            }
            else
            {
                cnt[j] = 0;
            }
        }

        bool is_answer = true;

        for (int times = 1; times <= x; ++times)
        {
            for (int bit = 16; bit >= 0; --bit)
            {
                if ((i & (1 << bit)) == 0)
                {
                    continue;
                }

                int need = 1;
                bool found = false;

                for (int j = bit; j >= 0; --j)
                {
                    if (cnt[j] >= need)
                    {
                        found = true;
                        cnt[j] -= need;
                        break;
                    }

                    need = 2 * need;
                }

                if (found == false)
                {
                    is_answer = false;
                    break;
                }
            }

            if (is_answer == false)
            {
                break;
            }
        }

        if (is_answer == true)
        {
            ++ans;
        }
    }

    return ans;
}

/*
1
3 3
5 2 1

1
3 2
2 1 2
*/

Compilation message (stderr)

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < a.size(); ++i)
      |                     ~~^~~~~~~~~~
biscuits.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if (j < a.size())
      |                 ~~^~~~~~~~~~
biscuits.cpp:16:9: warning: unused variable 'bits' [-Wunused-variable]
   16 |     int bits = 60;
      |         ^~~~
#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...