QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518794#8150. XOR SumAlorithmRE 1ms3944kbC++171.9kb2024-08-14 11:18:182024-08-14 11:18:19

Judging History

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

  • [2024-08-14 11:18:19]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3944kb
  • [2024-08-14 11:18:18]
  • 提交

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;
}

详细

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

output:


result: