QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#520047#1436. Split in SetszWA 1ms3904kbC++141.2kb2024-08-15 10:29:552024-08-15 10:29:55

Judging History

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

  • [2024-08-15 10:29:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3904kb
  • [2024-08-15 10:29:55]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
const ll MOD=1e9+7;
int n,k;
int a[N],b[N];
ll sum,ans=1,ans2;
ll jc[N],inv[N];
ll A(ll x,ll y){
	if(x<y) return 0;
	return jc[x]*inv[x-y]%MOD;
}
ll C(ll x,ll y){
	if(x<y) return 0;
	return jc[x]*inv[y]*inv[x-y]%MOD;
}
ll ksm(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1) ret=ret*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return ret;
}
int main(){
	scanf("%d%d",&n,&k);
	jc[0]=inv[0]=1;
	for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%MOD;
	inv[n]=ksm(jc[n],MOD-2);
	for(int i=n-1;i;i--) inv[i]=inv[i+1]*(i+1)%MOD;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int l=29;l>=0;l--){
		sort(a+1,a+n+1);
		int p=lower_bound(a+1,a+n+1,1<<l)-a;
		if(n-p+1<k){
			ans=ans*A(k,n-p+1)%MOD;
			for(int i=p;i<=n;i++) sum+=a[i];
			k-=n-p+1;
			n=p-1;
		}else if(p==1){
			sum+=(1ll<<l)*k;
			for(int i=1;i<=n;i++) a[i]-=1<<l;
		}else{
			sum+=(1ll<<l)*(k-1);
			for(int i=2;i<p;i++) a[1]&=a[i];
			for(int i=2;i<=n-p+2;i++) a[i]=a[i+p-2]-(1<<l);
			n=n-p+2;
		}
	}
	for(int i=1;i<=k;i++)
		(ans2+=(((k-i)&1)?-1:1)*C(k,i)*ksm(i,n)%MOD)%=MOD;
	printf("%lld %lld",sum,(ans*ans2%MOD+MOD)%MOD);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
4 7 5

output:

11 2

result:

ok 2 tokens

Test #2:

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

input:

4 1
44 47 74 77

output:

8 1

result:

ok 2 tokens

Test #3:

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

input:

4 4
44 47 74 77

output:

242 24

result:

ok 2 tokens

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3856kb

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:

35467198613 546955607

result:

wrong answer 2nd words differ - expected: '671056390', found: '546955607'