QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#829235#4283. Power of XORno_zzz_is_wwbndWA 1ms4004kbC++142.1kb2024-12-24 08:12:532024-12-24 08:12:55

Judging History

This is the latest submission verdict.

  • [2024-12-24 08:12:55]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 4004kb
  • [2024-12-24 08:12:53]
  • Submitted

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

bool ENDPOS = 0;
signed main()
{
	double BeginTime = clock();
	in(n); in(k);
	For(i, 1, n)
	{
		in(a[i]);
		ins(a[i]); 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 && n != 3)
	{
		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(s)]) % P;
		}
		printf("%lld\n", ans * ext % P);
	}
	else
	{
		int U = (1 << (n - cnt));
		For(i, 0, 43) if(p[i])
		{
			For(j, 0, i) if(p[i] >> j & 1)
			{
				if(!p[j]) q[i] |= (1 << 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: 1ms
memory: 3964kb

input:

3 2
1 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

2 1000000000
1 2

output:

140625003

result:

ok 1 number(s): "140625003"

Test #3:

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

input:

3 4
21 31 15

output:

1

result:

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