Submission #304979

#TimeUsernameProblemLanguageResultExecution timeMemory
304979MarcoMeijerPacking Biscuits (IOI20_biscuits)C++14
21 / 100
1085 ms71176 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
 
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
 
const ll MX=60, MX2=1e18+2;
 
ll x; vll a;
map<ll,ll> dp[MX];
 
void addDP(ll i, ll j, ll v) {
    if(j < 0) return;
    j /= 2;
    if(j >= MX2) j = MX2;
    dp[i][j] += v;
}
 
ll count_tastiness(ll X, vll A) {
    x=X; a=A;
 
    while(a.size() < MX) a.pb(0);
    RE(i,MX) {
        if(a[i] >= x+2) {
            ll rem = ((a[i]-x)/2ll)*2ll;
            a[i  ] -= rem;
            a[i+1] += rem/2ll;
        }
    }
 
    // base cases
    RE(i,MX) dp[i].clear();
    dp[0][a[0]] += 1;
    if(a[0]-x >= 0) dp[0][a[0]-x] += 1;
 
    REP(i,1,MX) {
        FOR(p,dp[i-1]) {
            addDP(i, (p.fi+2ll*a[i]), p.se);
            addDP(i, (p.fi+2ll*a[i]-2ll*x), p.se);
        }
    }
 
    ll ans = 0;
    FOR(p,dp[MX-1]) ans += p.se;
 
	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...