QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627828#8150. XOR SumlonelywolfAC ✓148ms6656kbC++201.7kb2024-10-10 17:17:352024-10-10 17:17:35

Judging History

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

  • [2024-10-10 17:17:35]
  • 评测
  • 测评结果:AC
  • 用时:148ms
  • 内存:6656kb
  • [2024-10-10 17:17:35]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

constexpr int mod = 1e9 + 7;

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

	int n, m, k;
	cin >> n >> m >> k;

	vector<int> a;
	while (m) {
		a.push_back(m % 2);
		m /= 2;
	}

	auto qpow = [&](int x, int y) {
		int res = 1;
		for (; y; y /= 2, x = x * x % mod) {
			if (y % 2) {
				res = res * x % mod;
			}
		}
		return res;
	};

	vector<int> fac(k + 1, 1), inv(k + 1, 1);
	for (int i = 1; i <= k; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = qpow(fac[i], mod - 2);
	}

	int mx = 0;
	for (int i = 0; i <= k; i++) {
		mx = max(mx, i * (k - i));
	}

	auto c = [&](int x, int y) {
		return fac[x] * inv[y] % mod * inv[x - y] % mod; 
	};

	int sz = a.size();
	vector dp(sz, vector(k + 1, map<int, int>()));

	function<int(int, int, int)> dfs = [&](int now, int x, int s) {
		if (now == -1) {
			if (s == 0) {
				return 1LL;
			} else {
				return 0LL;
			}
		}
		if (s < 0) {
			return 0LL;
		}
		if (mx * ((1LL << (now + 1)) - 1) < s) {
			return 0LL;
		}
		if (dp[now][x].count(s)) {
			return dp[now][x][s];
		}
		int ans = 0;
		if (a[now]) {
			for (int i = 0; i <= x; i++) {
				for (int j = 0; j <= k - x; j++) {
					int v = dfs(now - 1, i, s - (1LL << now) * (i + j) * (k - i - j));
					v = v * c(x, i) % mod * c(k - x, j) % mod;
					ans = (ans + v) % mod;
				}
			}
		} else {
			for (int i = 0; i <= k - x; i++) {
				int v = dfs(now - 1, x, s - (1LL << now) * i * (k - i));
				v = v * c(k - x, i) % mod;
				ans = (ans + v) % mod;
			}
		}
		dp[now][x][s] = ans;
		return ans;
	};

	cout << dfs(sz - 1, k, n) << "\n";

    return 0;
}  

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3856kb

input:

6 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

30 6 5

output:

1520

result:

ok 1 number(s): "1520"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

0 0 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

0 0 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

0 1145141919 2

output:

145141913

result:

ok 1 number(s): "145141913"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

0 0 18

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

0 12412414 18

output:

12412415

result:

ok 1 number(s): "12412415"

Test #8:

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

input:

32071009996106 682053093123 12

output:

443207413

result:

ok 1 number(s): "443207413"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

35533005762427 688386210611 9

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 65ms
memory: 6444kb

input:

35533005762427 688386210611 18

output:

132815685

result:

ok 1 number(s): "132815685"

Test #11:

score: 0
Accepted
time: 148ms
memory: 6564kb

input:

12412412412412 549755813887 18

output:

769139144

result:

ok 1 number(s): "769139144"

Test #12:

score: 0
Accepted
time: 44ms
memory: 4780kb

input:

12412412412412 549755813887 17

output:

256540093

result:

ok 1 number(s): "256540093"

Test #13:

score: 0
Accepted
time: 24ms
memory: 4440kb

input:

12412412412412 549755813887 15

output:

661919152

result:

ok 1 number(s): "661919152"

Test #14:

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

input:

8213830533897 180838478436 12

output:

960275439

result:

ok 1 number(s): "960275439"

Test #15:

score: 0
Accepted
time: 66ms
memory: 6444kb

input:

8213830533897 180838478436 18

output:

794870059

result:

ok 1 number(s): "794870059"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

56737445336495 759179417237 12

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 67ms
memory: 6304kb

input:

56737445336495 759179417237 18

output:

302105482

result:

ok 1 number(s): "302105482"

Test #18:

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

input:

56737445336495 759179417237 15

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 7ms
memory: 4520kb

input:

12412412412412 274877906944 18

output:

430003400

result:

ok 1 number(s): "430003400"

Test #20:

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

input:

32412412412412 274877906944 18

output:

657686236

result:

ok 1 number(s): "657686236"

Test #21:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

562949953421311 549755813887 18

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

985162418487295 549755813887 18

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

985162418487295 962072674303 18

output:

0

result:

ok 1 number(s): "0"

Test #24:

score: 0
Accepted
time: 145ms
memory: 6656kb

input:

35184372088831 962072674303 18

output:

665848241

result:

ok 1 number(s): "665848241"

Extra Test:

score: 0
Extra Test Passed