QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#477798#1436. Split in Setsxixi123WA 2ms5212kbC++141.8kb2024-07-14 10:39:532024-07-14 10:39:54

Judging History

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

  • [2024-07-14 10:39:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5212kb
  • [2024-07-14 10:39:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int n, k, a[maxn];
int fac[maxn + 5], ifac[maxn + 5];

int qpow(int a, int b)
{
	int sum = 1;
	while(b)
	{
		if(b & 1) sum = sum * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return sum;
}

void init()
{
	fac[0] = 1;
	for(int i = 1; i <= maxn; i++) fac[i] = fac[i - 1] * i % mod;
	ifac[maxn] = qpow(fac[maxn], mod - 2);
	for(int i = maxn - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
}

int A(int x, int y)
{
	return fac[x] * ifac[x - y] % mod;
}

int C(int x, int y)
{
	return fac[x] * ifac[x - y] % mod * ifac[y] % mod;
}

signed main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	
	init();
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int r1 = 0, r2 = 1;
	for(int i = 30; i; i--)
	{
		int cnt = 0;
		for(int j = 1; j <= n; j++) if((a[j] >> i) & 1) cnt++;
		if(!cnt) continue;
		if(cnt < k)
		{
			r2 = r2 * A(k, cnt) % mod;
			k -= cnt;
			int x = 0;
			for(int j = 1; j <= n; j++)
			{
				if((a[j] >> i) & 1)
				{
					r1 += a[j];
				}
				else a[++x] = a[j];
			}
			n = x;
		}
		else
		{
			if(cnt == n)
			{
				r1 += k << i;
				for(int j = 1;j <= n; j++)
				{
					a[j] = a[j] ^ (1 << i);
				}
			}
			else
			{
				r1 += (k - 1) << i;
				int x = 0, y = (1 << i) - 1;
				for(int j = 1; j <= n; j++)
				{
					if((a[j] >> i) & 1) a[++x] = a[j] ^ (1 << i);
					else y &= a[j];
				}
				a[++x] = y;
				n = x;
			}
		}
	}
	int f = 0;
	for(int i = 1; i <= k; i++)
	{
		int g = qpow(i, n) * C(k, i) % mod;
		if((k - i) & 1) f -= g;
		else f += g;
	}
	cout << r1 << " " << ((f % mod + mod) % mod * r2) % mod;
	return 0;
}
/*
3 2
4 7 5


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5188kb

input:

3 2
4 7 5

output:

11 2

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 2ms
memory: 5136kb

input:

4 1
44 47 74 77

output:

8 1

result:

ok 2 tokens

Test #3:

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

input:

4 4
44 47 74 77

output:

242 24

result:

ok 2 tokens

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 5212kb

input:

1000 975
633065 7087 25267 3940676 618039 1695 2043 728466935 3498 13604984 4 99 119488 151315 12 32 52705062 26815 1902279 33952 480604 390647001 60 1 12566875 7591859 6 119892 7829822 2129 4 11644639 17 33200 5330 338 2 9 6862 3781 148087 57 198 13224999 10493180 1 5755424 216 1757297 210 1002623 ...

output:

35467198591 447058217

result:

wrong answer 1st words differ - expected: '35467198613', found: '35467198591'