QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#520692#1436. Split in SetscqzhmWA 2ms5308kbC++141.4kb2024-08-15 14:58:132024-08-15 14:58:14

Judging History

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

  • [2024-08-15 14:58:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5308kb
  • [2024-08-15 14:58:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e5+10;
const int mod=1e9+7;
int n,k;
int fac[MAXN],inv[MAXN];
int a[MAXN];
inline void init(){
    fac[0]=inv[0]=inv[1]=1;
    for(int i=2;i<MAXN;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<MAXN;i++) inv[i]=inv[i-1]*inv[i]%mod,fac[i]=fac[i-1]*i%mod;
}
inline int C(int n,int m){
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod; b>>=1;
	}
	return ans;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k; init();
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans1=0,ans2=1;
	for(int i=30;i>=0;i--){
		int cnt=0;
		for(int j=1;j<=n;j++) cnt+=((a[j]>>i)&1);
		if(cnt<=k){
			ans2=ans2*C(k,cnt)%mod*fac[cnt]%mod;
			k-=cnt; int x=0;
			for(int j=1;j<=n;j++){
				if((a[j]>>i)&1) ans1+=a[j];
				else a[++x]=a[j];
			}
			n=x;
		}
		else{
			if(cnt==n){
				ans1+=(1<<i)*k;
				for(int j=1;j<=n;j++) a[j]^=(1<<i);
			}
			else{
				ans1+=(1<<i)*(k-1);
				int and_sum=(1<<30)-1,x=0;
				for(int j=1;j<=n;j++){
					if((a[j]>>i)&1) a[++x]=a[j]^(1<<i);
					else and_sum&=a[j];
				}
				a[++x]=and_sum; n=x;
			}
		}
	}
	int sum=0;
	for(int i=1;i<=k;i++) sum=(sum+ksm(i,n)*C(k,i)%mod*((k-i)&1?-1:1)+mod)%mod;
	cout<<ans1<<" "<<(ans2*sum%mod+mod)%mod<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5308kb

input:

3 2
4 7 5

output:

12 0

result:

wrong answer 1st words differ - expected: '11', found: '12'