이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int k = 60;
long long x;
long long biscuits[k];
long long sum[k][k], mask[k][k];
vector<int> ind[k];
long long solutions;
vector<int> sol;
void countSolutions( int b, long long s ) {
solutions++;
//for ( int i: sol )
// printf( "%d ", i );
//printf( "\n" );
for ( int i: ind[b] ) {
long long cs = ((s / 2 + mask[b][i]) >> (i - b)) + sum[b][i];
// printf( "%d %d %d\n", b, i, cs );
if ( cs >= x )
countSolutions( i + 1, cs - x );
else
break;
}
}
int p;
bool cmp( int p1, int p2 ) {
//long long r1 = ((mask[p][p1] >> (p1 - p)) + sum[p][p1] - x) >> p2, r2 = ((mask[p][p2] >> (p2 - p)) + sum[p][p2] - x) >> p1;
return ((__int128)mask[p][p1] << p) + (((__int128)sum[p][p1] - x) << p1) > ((__int128)mask[p][p2] << p) + (((__int128)sum[p][p2] - x) << p2);
}
long long count_tastiness( long long X, vector <long long> a ) {
long long s;
x = X;
a.resize( k );
s = 0;
for ( int b = 0; b < k; b++ ) {
a[b] += s;
if ( a[b] > x ) {
s = a[b] - x;
a[b] = x + s % 2;
s /= 2;
} else
s = 0;
biscuits[b] = a[b];
}
for ( int i = 0; i < k; i++ ) {
sum[i][i] = biscuits[i];
for ( int j = i + 1; j < k; j++ ) {
mask[i][j] = mask[i][j - 1] + (((long long)sum[i][j - 1] % 2) << (j - i - 1));
sum[i][j] = sum[i][j - 1] / 2 + biscuits[j];
//printf( "%d %d: %d %d\n", i, j, sum[i][j], mask[i][j] );
}
}
for ( int b = 0; b < k; b++ ) {
ind[b].clear();
for ( int i = b; i < k; i++ )
ind[b].push_back( i );
p = b;
sort( ind[b].begin(), ind[b].end(), cmp );
}
solutions = 0;
countSolutions( 0, 0 );
return solutions;
}
# | 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... |