(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #335541

#TimeUsernameProblemLanguageResultExecution timeMemory
335541aanastasovPacking Biscuits (IOI20_biscuits)C++17
100 / 100
33 ms1004 KiB
#include "biscuits.h" #include <cassert> //#include <iostream> typedef long long int64_t; int64_t count_tastiness(int64_t numGroups, std::vector<int64_t> initialCount) { while (initialCount.size() < 62) initialCount.push_back(0); int64_t spareCount = 0; auto numWays = std::vector<int64_t>{1}; for (int64_t i = 0; i < initialCount.size(); ++i) { if (initialCount[i] + spareCount >= numGroups) { spareCount = spareCount + initialCount[i] - numGroups; assert(spareCount >= 0); numWays.push_back(numWays.back() * 2); } else { int64_t maxPossible = 0; int64_t availableQty = 0; for (int64_t j = 0; j <= i; ++j) availableQty += initialCount[j] << j; int64_t borrowedQty = 0; for (int64_t j = i; j >= 0; --j) { assert(availableQty >= borrowedQty); assert((borrowedQty % (1LL << j)) == 0); int64_t curCount = initialCount[j]; if ((curCount << j) <= borrowedQty) { borrowedQty -= curCount << j; availableQty -= curCount << j; curCount = 0; } else { curCount -= borrowedQty >> j; availableQty -= borrowedQty; borrowedQty = 0; } assert(curCount >= 0 && curCount <= initialCount[j]); if (((availableQty - borrowedQty) >> j) < numGroups) { availableQty -= curCount << j; continue; } borrowedQty += numGroups << j; borrowedQty = std::max(0LL, borrowedQty - (curCount << j)); availableQty -= curCount << j; maxPossible |= 1LL << j; } assert(borrowedQty == 0); int64_t curWays = 0; for (int64_t j = 0; j < i + 1; ++j) { if (((maxPossible + 1) & (1LL << j)) > 0) curWays += numWays[j]; } numWays.push_back(curWays); spareCount = 0; } spareCount >>= 1LL; } return numWays.back(); }

Compilation message (stderr)

biscuits.cpp: In function 'int64_t count_tastiness(int64_t, std::vector<long long int>)':
biscuits.cpp:12:27: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int64_t i = 0; i < initialCount.size(); ++i) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
#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...