This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "biscuits.h"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
const int MAXK = 60;
int a[MAXK + 10];
map<pii, int> mem;
int dp(int k, int cur, int x) {
cur /= 2;
if(k < MAXK) cur += a[k];
pii key(k, cur);
if(mem.count(key)) return mem[key];
if(k >= MAXK) return mem[key] = cur + 1;
return mem[key] = dp(k + 1, cur, x) + (cur < x ? 0 : dp(k + 1, cur - x, x));
}
// long long count_tastiness_2(long long x, std::vector<long long> _a) {
// memset(a, 0, sizeof(a));
// int k = sz(_a);
// int su = 0;
// For(i, 0, k - 1) {
// a[i] = _a[i];
// su += (1ll << i) * a[i];
// }
// int ans = 0;
// For(s, 0, su) {
// int cur = 0;
// bool fail = false;
// For(i, 0, 19) {
// cur = cur / 2 + a[i];
// if(s & (1 << i)) cur -= x;
// if(cur < 0) {
// fail = true;
// break;
// }
// }
// if(!fail) ans++;
// }
// return ans;
// }
long long count_tastiness(long long x, std::vector<long long> _a) {
memset(a, 0, sizeof(a));
mem.clear();
int k = sz(_a);
For(i, 0, k - 1) {
a[i] = _a[i];
}
// cerr << count_tastiness_2(1, _a) << "\n";
return dp(0, 0, x);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |