Submission #661143

#TimeUsernameProblemLanguageResultExecution timeMemory
661143evenvaluePacking Biscuits (IOI20_biscuits)C++17
12 / 100
1 ms596 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

using int64 = long long;
using ld = long double;

constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
constexpr int kBits = 60;

int64 calc(const vector<int64> &biscuits) {
  int64 ans = 1;
  for (int i = 0; i < biscuits.size(); i++) {
    ans += (1LL << i) * biscuits[i];
  }
  return ans;
}

int64 count_tastiness(int64 x, vector<int64> biscuits) {
  biscuits.push_back(0);

  assert(x == 1);

  vector<vector<int64>> segments = {{}};

  for (int64 i = 0, carry = 0; i < biscuits.size(); i++) {
    biscuits[i] += carry;
    carry = (biscuits[i] - 1) / 2;
    if (biscuits[i] == 0) {
      segments.emplace_back();
    } else {
      segments.back().push_back(biscuits[i] - carry * 2);
    }
    if (i == biscuits.size() - 1 and carry) biscuits.push_back(0);
  }

  int64 ans = 1;
  for (const auto &segment : segments) {
    ans *= calc(segment);
  }

  return ans;
}

Compilation message (stderr)

biscuits.cpp: In function 'int64 calc(const std::vector<long long int>&)':
biscuits.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < biscuits.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~
biscuits.cpp: In function 'int64 count_tastiness(int64, std::vector<long long int>)':
biscuits.cpp:33:34: warning: comparison of integer expressions of different signedness: 'int64' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for (int64 i = 0, carry = 0; i < biscuits.size(); i++) {
      |                                ~~^~~~~~~~~~~~~~~~~
biscuits.cpp:41:11: warning: comparison of integer expressions of different signedness: 'int64' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     if (i == biscuits.size() - 1 and carry) biscuits.push_back(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...