Submission #638695

#TimeUsernameProblemLanguageResultExecution timeMemory
638695slimePacking Biscuits (IOI20_biscuits)C++14
0 / 100
1096 ms340 KiB
#include "biscuits.h"
#include "bits/stdc++.h"
using namespace std;

bool check(long long x, __int128 y, std::vector<long long> a) {

  int k = a.size();
  for(long long i=0; i<x; i++) {
    __int128 w = y;
    for(int j=k-1; j>=0; j--) {
      __int128 nd = w / (1ll << j);
      nd = min(nd, (__int128) a[j]);

      a[j] -= nd;
      w -= nd * (1ll << j);
    }
    if(w) return 0;
    if(i < x-1) {
      bool phew = 0;
      for(int j=0; j<k; j++) phew |= (a[j] > 0);
      if(!phew) return 0;
    }
  }
  return 1;
}

long long count_tastiness(long long x, std::vector<long long> a) {

  __int128 nxt = -1;
  __int128 mul = 1;
  __int128 ans = 1;

  while(1) {
    nxt++;


    if(!check(x, nxt * mul, a)) { // find next perfect power, e.g. 6 -> 8
      long long lg = 64 - __builtin_clzll(nxt) - 1;
      lg = mul * (1ll << (lg + 1)); 
      mul = lg;
      // if [0, 9] ok, 10 not ok, ans *= nxt

      if(nxt == 1) break;
      ans *= nxt;
      nxt = 0;
    }

  }

  ans *= nxt;
  return ans;
}
#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...