QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#313313#8150. XOR SumPetroTarnavskyi#AC ✓75ms14104kbC++201.9kb2024-01-24 17:23:202024-01-24 17:23:22

Judging History

你现在查看的是最新测评结果

  • [2024-01-24 17:23:22]
  • 评测
  • 测评结果:AC
  • 用时:75ms
  • 内存:14104kb
  • [2024-01-24 17:23:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int mod = 1'000'000'007;
const int N = 1 << 20;
const int LOG = 52;
const int K = 19;

int fact[N], ifact[N];

int mult(int a, int b)
{
	return (LL) a * b % mod;
}
int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}
void updAdd(int& a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}
int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

void init()
{
	fact[0] = 1;
	FOR(i, 1, N)
		fact[i] = mult(fact[i - 1], i);
	ifact[N - 1] = binpow(fact[N - 1], mod - 2);
	RFOR(i, N, 1)
		ifact[i - 1] = mult(ifact[i], i);
}

int C(int n, int k)
{
	return mult(fact[n], mult(ifact[n - k], ifact[k]));
}

int getBit(LL n, int i)
{
	return (n >> i) & 1;
}

LL m;
int k;
unordered_map<LL, int> dp[LOG][K];

int f(int pos, int cnt, LL n)
{
	if (n > (k / 2) * (k + 1) / 2 * ((1LL << pos) - 1))
		return 0;
	if (pos == 0)
		return 1;
	if (dp[pos][cnt].count(n))
		return dp[pos][cnt][n];
	int& res = dp[pos][cnt][n];
	int b = getBit(m, pos - 1);
	int v = b ? cnt : 0;
	FOR(i, 0, v + 1)
	{
		FOR(j, 0, k - cnt + 1)
		{
			LL nn = n - (((LL)(i + j) * (k - i - j)) << (pos - 1));
			if (nn >= 0)
				updAdd(res, mult(mult(C(cnt, i), C(k - cnt, j)), f(pos - 1, b ? i : cnt, nn)));
		}
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	init();
	LL n;
	cin >> n >> m >> k;
	cout << f(LOG - 1, k, n) << "\n";
	return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 11780kb

input:

6 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 12ms
memory: 11864kb

input:

30 6 5

output:

1520

result:

ok 1 number(s): "1520"

Test #3:

score: 0
Accepted
time: 12ms
memory: 12064kb

input:

0 0 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 12ms
memory: 11840kb

input:

0 0 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 9ms
memory: 11872kb

input:

0 1145141919 2

output:

145141913

result:

ok 1 number(s): "145141913"

Test #6:

score: 0
Accepted
time: 9ms
memory: 11784kb

input:

0 0 18

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 12ms
memory: 11796kb

input:

0 12412414 18

output:

12412415

result:

ok 1 number(s): "12412415"

Test #8:

score: 0
Accepted
time: 17ms
memory: 12324kb

input:

32071009996106 682053093123 12

output:

443207413

result:

ok 1 number(s): "443207413"

Test #9:

score: 0
Accepted
time: 9ms
memory: 12028kb

input:

35533005762427 688386210611 9

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 47ms
memory: 13896kb

input:

35533005762427 688386210611 18

output:

132815685

result:

ok 1 number(s): "132815685"

Test #11:

score: 0
Accepted
time: 75ms
memory: 13992kb

input:

12412412412412 549755813887 18

output:

769139144

result:

ok 1 number(s): "769139144"

Test #12:

score: 0
Accepted
time: 35ms
memory: 12668kb

input:

12412412412412 549755813887 17

output:

256540093

result:

ok 1 number(s): "256540093"

Test #13:

score: 0
Accepted
time: 17ms
memory: 12352kb

input:

12412412412412 549755813887 15

output:

661919152

result:

ok 1 number(s): "661919152"

Test #14:

score: 0
Accepted
time: 16ms
memory: 12548kb

input:

8213830533897 180838478436 12

output:

960275439

result:

ok 1 number(s): "960275439"

Test #15:

score: 0
Accepted
time: 38ms
memory: 13808kb

input:

8213830533897 180838478436 18

output:

794870059

result:

ok 1 number(s): "794870059"

Test #16:

score: 0
Accepted
time: 8ms
memory: 11844kb

input:

56737445336495 759179417237 12

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 33ms
memory: 13840kb

input:

56737445336495 759179417237 18

output:

302105482

result:

ok 1 number(s): "302105482"

Test #18:

score: 0
Accepted
time: 13ms
memory: 12184kb

input:

56737445336495 759179417237 15

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 12ms
memory: 12528kb

input:

12412412412412 274877906944 18

output:

430003400

result:

ok 1 number(s): "430003400"

Test #20:

score: 0
Accepted
time: 12ms
memory: 13236kb

input:

32412412412412 274877906944 18

output:

657686236

result:

ok 1 number(s): "657686236"

Test #21:

score: 0
Accepted
time: 12ms
memory: 11792kb

input:

562949953421311 549755813887 18

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 12ms
memory: 11836kb

input:

985162418487295 549755813887 18

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 12ms
memory: 11864kb

input:

985162418487295 962072674303 18

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 69ms
memory: 14104kb

input:

35184372088831 962072674303 18

output:

665848241

result:

ok 1 number(s): "665848241"

Extra Test:

score: 0
Extra Test Passed