QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518794 | #8150. XOR Sum | Alorithm | RE | 1ms | 3944kb | C++17 | 1.9kb | 2024-08-14 11:18:18 | 2024-08-14 11:18:19 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
const i64 mod = 1e9 + 7;
vector C(50, vector<i64>(50));
i64 n, m;
int k, cnt;
vector<int> a;
map<i64, i64> dp[60][50];
void init() {
C[0][0] = 1;
C[1][0] = C[1][1] = 1;
for (int i = 1; i <= 30; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++) {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
if (C[i][j] >= mod)
C[i][j] -= mod;
}
}
}
int dfs(int cur, int limit, int lv) {
if (lv < 0)
return 0;
if (cur < 0)
return lv == 0;
int s1 = k / 2, s0 = k - s1;
if (((1ll << cur + 1) - 1) * s0 * s1 < lv)
return 0;
if (dp[cur][limit].count(lv))
return dp[cur][limit][lv];
i64 res = 0;
if (a[cur] == 1) {
for (int i = 0; i <= limit; i++) {
for (int j = 0; j <= k - limit; j++) {
i64 val = 1ll * (k - i - j) * (i + j) * (1ll << cur);
i64 t = C[limit][i] * C[k - limit][j] % mod;
res += t * dfs(cur - 1, i, lv - val) % mod;
res %= mod;
}
}
} else {
for (int i = 0; i <= 0; i++) {
for (int j = 0; j <= k - limit; j++) {
i64 val = 1ll * (k - i - j) * (i + j) * (1ll << cur);
i64 t = C[limit][i] * C[k - limit][j] % mod;
res += t * dfs(cur - 1, limit, lv - val) % mod;
res %= mod;
}
}
}
return dp[cur][limit][lv] = res;
}
void solve() {
cnt = 0;
a.clear();
cin >> n >> m >> k;
while (m) {
a.push_back(m & 1);
m >>= 1;
cnt++;
}
cout << dfs(cnt, k, n) << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3944kb
input:
6 2 3
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
30 6 5
output:
1520
result:
ok 1 number(s): "1520"
Test #3:
score: -100
Runtime Error
input:
0 0 1