QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#829245#4283. Power of XORno_zzz_is_wwbndWA 1ms4096kbC++142.2kb2024-12-24 08:25:362024-12-24 08:25:37

Judging History

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

  • [2024-12-24 08:25:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4096kb
  • [2024-12-24 08:25:36]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <ctime>
#include <cassert>

using namespace std;

#define int long long
#define PII pair<int,int>
#define x first
#define y second
#define For(i, l, r) for(int i = l; i <= r; i ++)
#define Rep(i, l, r) for(int i = l; i >= r; i --)

bool START;

void in(int &x)
{
	char c = getchar(); int op = 1;
	while(c > '9' || c < '0') op *= (c == '-' ? -1 : 1), c = getchar();
	for(x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= op;
}

const int N = 50, P = 1e9 + 7;

int ksm(int x, int y)
{
	int s = 1;
	while(y)
	{
		if(y & 1) s = s * x % P; x = x * x % P; y >>= 1;
	}
	return s;
}

int n, m, k;
int a[N], p[N], cnt, pw[N], q[N], ans;
int dp[1 << 25];
int f[46][1 << 19];

void ins(int v)
{
	Rep(i, 43, 0) if(v >> i & 1)
	{
		if(!p[i]) {p[i] = v; cnt ++; break;}
		v ^= p[i];
	}
}
int id[55];

bool ENDPOS = 0;
signed main()
{
	double BeginTime = clock();
	in(n); in(k);
	For(i, 1, n)
	{
		in(a[i]);
		ins(a[i]);
	}
	For(i, 1, 44) pw[i] = ksm(i, k);
	For(i, 0, 43)
	{
		Rep(j, i - 1, 0) if(p[j])
		{
			if(p[i] >> j & 1) p[i] ^= p[j];
		}
	}
	int ext = ksm(2, n - cnt);
	if(cnt <= 25)
	{
		int U = (1 << cnt);
		int ddos = 0;
		For(i, 0, 43) if(p[i]) q[ddos ++] = i;
		For(s, 1, U - 1)
		{
			dp[s] = dp[s & (s - 1)] ^ p[q[__builtin_ctz(s)]];
			ans = (ans + pw[__builtin_popcount(dp[s])]) % P;
			cerr << dp[s] << endl;
		}
		printf("%lld\n", ans * ext % P);
	}
	else
	{
		int U = (1 << (44 - cnt)); int no = 0;
		For(i, 0, 43) if(!p[i]) id[i] = no ++;
		For(i, 0, 43) if(p[i])
		{
			For(j, 0, i) if(p[i] >> j & 1)
			{
				if(!p[j]) q[i] |= (1 << id[j]);
			}
		}
		int ns = 0; f[0][0] = 1;
		For(i, 0, 43) if(p[i])
		{
			Rep(j, ns, 0) For(k, 0, U - 1) (f[j + 1][k ^ q[i]] += f[j][k]) %= P;
			ns ++;
		}
		For(i, 1, n) For(s, 0, U - 1) ans = (ans + pw[__builtin_popcount(s) + i] * f[i][s]) % P;
		printf("%lld\n", ans * ext % P);
	}
	cerr << "Time = " << (clock() - BeginTime) * 1.0 / CLOCKS_PER_SEC << " s" << endl;
	cerr << "Memory = " << (&ENDPOS - &START) * 1.0 / 1024 / 1024 << " Mib" << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3924kb

input:

3 2
1 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

2 1000000000
1 2

output:

140625003

result:

ok 1 number(s): "140625003"

Test #3:

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

input:

3 4
21 31 15

output:

1076

result:

ok 1 number(s): "1076"

Test #4:

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

input:

4 10
21 16 23 30

output:

3504120

result:

ok 1 number(s): "3504120"

Test #5:

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

input:

5 795325759
23 18 18 15 24

output:

398580583

result:

ok 1 number(s): "398580583"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 4096kb

input:

6 425010546
15190825693299 11021868218180 10853490476696 16489831131502 15731786397897 1859285400474

output:

899135263

result:

wrong answer 1st numbers differ - expected: '226806798', found: '899135263'