Submission #390893

# Submission time Handle Problem Language Result Execution time Memory
390893 2021-04-17T10:27:25 Z AlexPop28 Packing Biscuits (IOI20_biscuits) C++14
0 / 100
2 ms 1228 KB
#include "biscuits.h"
#include <bits/stdc++.h>

using namespace std;

int n;

/*
long long Solve(int i, vector<long long> cnt) {
  if (i == (int)cnt.size()) {
    return 1LL;
  }

  if (cnt[i] > n + 1) {
    if (i + 1 == (int)cnt.size()) {
      cnt.emplace_back(0LL);
    }
    auto delta = (cnt[i] - n) / 2;
    cnt[i + 1] += delta;
    cnt[i] -= 2 * delta;
  }

  if (cnt[i] < n) {
    return Solve(i + 1, cnt);
  }
  long long ret = Solve(i + 1, cnt);
  if (i + 1 == (int)cnt.size()) {
    cnt.emplace_back(0LL);
  }
  cnt[i + 1] += cnt[i] / 2;
  ret += Solve(i + 1, cnt);
  return ret; 
}
*/

long long Solve(int i, vector<long long> cnt, long long s) {
  if (i == (int)cnt.size() && s < (n << i)) {
    // cerr << "br 1: " << s << '\n';
    return 1LL;
  }
  if (i == (int)cnt.size()) {
    // cerr << "b: " << s << '\n';
    return Solve(i + 1, cnt, s - (n << i));
  }

  if (cnt[i] < n) {
    long long ret = Solve(i + 1, cnt, s + (cnt[i] << i));
    if (s + (cnt[i] << i) >=  (n << i)) {
      ret += Solve(i + 1, cnt, s + (cnt[i] << i) - (n << i));
    }
    return ret;
  }
  long long ret = Solve(i + 1, cnt, s + ((cnt[i] - n) << i));
  ret += Solve(i + 1, cnt, s + (cnt[i] << i));
  // cerr << i << ' ' << s << ' ' << ret << endl;
  return ret; 
}

long long count_tastiness(long long n, vector<long long> a) {
  ::n = n;
  for (int i = 0; i < (int)a.size(); ++i) {
    if (a[i] > n + 1) {
      if (i + 1 == (int)a.size()) a.emplace_back(0LL);
      auto delta = (a[i] - n) / 2;
      a[i + 1] += delta;
      a[i] -= 2 * delta;
    }
    // cerr << a[i] << ' ';
  }
  // cerr << endl;

  return Solve(0, a, 0);
}

# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -