QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823118#4283. Power of XORyuanruiqiWA 19ms96124kbC++141.8kb2024-12-20 19:30:292024-12-20 19:30:29

Judging History

This is the latest submission verdict.

  • [2024-12-20 19:30:29]
  • Judged
  • Verdict: WA
  • Time: 19ms
  • Memory: 96124kb
  • [2024-12-20 19:30:29]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int maxn = 45;
constexpr int maxm = 18;
constexpr int mod = 1000000000 + 7;
i64 qp(i64 a, i64 b)
{
    i64 c = 1;
    for (; b; b>>=1, a=a*a%mod)
        if (b & 1) c=c*a%mod;
    return c;
}
i64 a[maxn], p[maxn];
i64 f[1 << maxm][maxn], g[1 << maxm][maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i=0;i<n;++i)
    {
        i64 x;
        cin >> x;
        for (int j=n-1;j>=0;--j)
            if (x >> j & 1)
            {
                if (!a[j]) a[j] = x;
                x ^= a[j];
            }
    }
    for (int i=n-1;i;--i)
        for (int j=i-1;j>=0;--j)
            if ((a[i] >> j & 1) && a[j]) a[i] ^= a[j];
    for (int i=0;i<=n;++i) p[i] = qp(i, k);
    vector<int> u, v;
    for (int i=0;i<n;++i) (a[i] ? u : v).emplace_back(i);
    i64 ans = 0;
    if (v.size() > 18)
    {
        for (int i=0;i<(1<<u.size());++i)
        {
            i64 x = 0;
            for (int j=0;j<u.size();++j) if (i >> j & 1) x ^= a[u[j]];
            ans += p[__builtin_popcount(x)];
        }
        cout << ((ans % mod) << n - u.size()) % mod << '\n';
        return 0;
    }
    int m = v.size();
    f[0][0] = 1;
    for (int i=0;i<u.size();++i)
    {
        memcpy(g, f, sizeof(f));
        i64 s = 0;
        for (int j=0;j<m;++j) if (a[u[i]] >> v[j] & 1) s |= 1 << j;
        for (int x=0;x<(1<<m);++x)
            for (int y=0;y<=i;++y)
                (f[x ^ s][y + 1] += g[x][y]) %= mod;
    }
    for (int x=0;x<(1<<m);++x)
        for (int y=0;y<=u.size();++y)
            (ans += p[__builtin_popcount(x) + y] * f[x][y]) %= mod;
    cout << ((ans % mod) << n - u.size()) % mod << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 19ms
memory: 95956kb

input:

3 2
1 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 3ms
memory: 95872kb

input:

2 1000000000
1 2

output:

140625003

result:

ok 1 number(s): "140625003"

Test #3:

score: -100
Wrong Answer
time: 17ms
memory: 96124kb

input:

3 4
21 31 15

output:

196

result:

wrong answer 1st numbers differ - expected: '1076', found: '196'