제출 #304001

#제출 시각아이디문제언어결과실행 시간메모리
304001Fdg비스킷 담기 (IOI20_biscuits)C++14
100 / 100
175 ms1024 KiB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

map<pair<int, long long>, long long> f;
vector<long long> arr;
vector<long long> sums;

long long solve3(long long x, int pos, long long sub) {
  if (pos == -1) return sub == 0;
  if (f.count({pos, sub})) return f[{pos, sub}];

  long long cur = pos < (int) arr.size() ? arr[pos] : 0;

  long long ret = 0;
  if ((1LL << pos) <= (sums[pos] - sub) / x) {
    long long what = solve3(x, pos - 1, max(0LL, sub + x * (1LL << pos) - (1LL << pos) * cur));
    ret += what;
    if (what == (1LL << pos)) {
      ret += what;
      return f[{pos, sub}] = ret;
    }
  }

  ret += solve3(x, pos - 1, max(0LL, sub - (1LL << pos) * cur));

  return f[{pos, sub}] = ret;
}

long long count_tastiness(long long x, vector<long long> a) {
  f.clear(); sums.clear();

  long long s = 0, pw = 1;
  for (int i = 0; i < 60; ++i) {
    if (i < (int) a.size())
      s += pw * a[i];
    pw <<= 1;
    sums.push_back(s);
  }

  arr = a;
  return solve3(x, 59, 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...