제출 #362631

#제출 시각아이디문제언어결과실행 시간메모리
362631valerikk비스킷 담기 (IOI20_biscuits)C++17
21 / 100
1097 ms492 KiB
#include <bits/stdc++.h>
 
using namespace std; 
 
typedef long long ll;
 
ll count_tastiness(ll x, vector<ll> a) {
    const int k = 60;
    while ((int)a.size() < k + 1) a.push_back(0LL);
    if (x == 1LL) {
        for (int i = 0; i < k; i++) {
            ll z = (a[i] - 1LL) / 2LL;
            a[i + 1] += z;
            a[i] -= 2LL * z;
        }
        vector<ll> dp(2, 0LL);
        dp[0] = 1LL;
        for (int i = 0; i < k; i++) {
            vector<ll> ndp(2, 0LL);
            for (int carry = 0; carry < 2; carry++) {
                assert(a[i] >= 0 && a[i] <= 2);
                int cur = carry + a[i];
                ndp[cur / 2LL] += dp[carry];
                if (cur > 0LL) ndp[(cur - 1LL) / 2LL] += dp[carry]; 
            }
            dp.swap(ndp);
        }
        return dp[0] + dp[1];
    }
    ll res = 0;
    for (ll y = 0LL; y <= 100000LL; y++) {
        auto a_copy = a;
        bool can = true;
        for (int i = 0; i < k; i++) {
            ll need = x * ((y >> i) & 1LL);
            if (a[i] < need) {
                can = false;
                break;
            }
            a[i] -= need;
            a[i + 1] += a[i] / 2LL;
        }
        if (can) res++;
        a = a_copy;
    }
    return res;
}
 
#ifdef LOCAL
int main() {
    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    ll x;
    cin >> k >> x;
    vector<ll> a(k);
    for (ll &z : a) cin >> z;
    cout << count_tastiness(x, a);
    return 0;
}
#endif
#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...