제출 #1175553

#제출 시각아이디문제언어결과실행 시간메모리
1175553hyakupPacking Biscuits (IOI20_biscuits)C++20
0 / 100
161 ms287880 KiB
#include "biscuits.h" #include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e18 + 10; const int maxn = 61; const int maxx = 2e4; ll dp[maxn][maxn][maxx]; ll count_tastiness( ll x, vector<ll> a ){ for( int i = 0; i < (int)a.size(); i++ ){ if( a[i] >= x ){ if( i == (int)a.size() - 1 ) a.push_back(0); ll aux = (a[i] - x)/2; a[i + 1] += aux; a[i] -= 2*aux; } } a.push_back(0); if( x >= maxx ) return 0; int n = a.size(); for( int i = 0; i < n; i++ ) for( int j = 0; j < n; j++ ) for( int k = 0; k < x + 10; k++ ) dp[i][j][k] = -1; int max_shift = 0; for( int i = 0; i < n; i++ ){ if( (x<<i) > inf ) break; max_shift = i; } function<ll( int, int, ll, ll )> solve = [&]( int i, int j, ll remain, ll num ){ if( i < 0 ) return 1LL; if( dp[i][j][remain] != -1 ) return dp[i][j][remain]; ll &resp = dp[i][j][remain]; resp = solve( i - 1, j, remain, num); if( i >= max_shift ) return resp; ll goal = (x<<i); if( j > i ){ j = i; remain = a[i]; } if( (remain<<j) >= goal ){ ll qtd = (goal>>j); remain -= qtd; ll aux = solve( i - 1, j, remain, num + (1LL<<i) ); // cout << "1 " << resp + aux << endl; return resp + aux; } goal -= (remain<<j); j--; while( j >= 0 ){ if( (a[j]<<j) >= goal ){ ll qtd = (goal>>j); remain = a[j] - qtd; ll aux = solve( i - 1, j, remain, num + (1LL<<i) ); // cout << "2 " << resp + aux << endl; return resp + aux; } goal -= (a[j]<<j); j--; } // cout << "3 " << resp << endl; return resp; }; return solve( n - 1, n - 1, a[n - 1], 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...