QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#521008#1436. Split in Setsc20251515Compile Error//C++141.7kb2024-08-15 19:48:532024-08-15 19:48:53

Judging History

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

  • [2024-08-15 19:48:53]
  • 评测
  • [2024-08-15 19:48:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10,mod=1e9+7;
ll n,K,a[N],ans1=0,ans2=1;
ll fac[N],inv[N];
ll maxn=0;
bool vis[N];
vector<ll> p;
ll ksm(ll x,ll k){
	ll tmp=1;
	while(k){
		if(k%2==1) tmp=tmp*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return tmp;
}
void init(){
	fac[0]=1;
	for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=ksm(fac[1000000],mod-2);
	for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
ll c(ll x,ll y){
	if(x<y) return 0;
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void get(ll x){
	ll now=0;
	while(x){
		x/=2;
		now++;
	}
	maxn=max(maxn,now-1);
}
ll strling(ll x,ll y){
	if(x<y) return 0;
	if(y==0) return 0;
	if(x==y) return 1;
	if(y==1) return 1;
	return (strling(x-1,y-1)+y*strling(x-1,y)%mod)%mod;
}
void dfs(vector<ll> s,ll k,ll deep){
	if((ll)s.size()<k) exit(0);
	ll cnt0=0,cnt1=0;
	for(auto x:s){
		if(x&(1ll<<deep)) cnt1++;
		else cnt0++;
	}
	ans1+=(1ll<<deep)*min(k-(cnt0>0),cnt1));
	if(deep==0){
		if(cnt1>=k) ans2=ans2*strling(cnt1+1,k)%mod;
		else ans2=ans2*strling(cnt0,k-cnt1)%mod;
		return;
	}
	if(cnt1>=k){
		ll tmp=INT_MAX;
		vector<ll> record;
		for(auto x:s){
			if(x&(1ll<<deep)) record.push_back(x);
			else tmp&=x;
		}
		if(cnt0) record.push_back(tmp);
		dfs(record,k,deep-1);
	}
	else{
		vector<ll> record;
		for(auto x:s){
			if((x&(1ll<<deep))==0) record.push_back(x);
			else ans1=(ans1+(x&((1ll<<deep)-1)))%mod;
		}
		dfs(record,k-cnt1,deep-1);
	}
}
int main(){
	cin>>n>>K;
	init();
	for(int i=1;i<=n;i++){
		cin>>a[i];
		get(a[i]);
		p.push_back(a[i]);
	}
	dfs(p,K,maxn);
	ans2=ans2*fac[K]%mod;
	cout<<ans1<<" "<<ans2;
	return 0;
}

Details

answer.code: In function ‘void dfs(std::vector<long long int>, ll, ll)’:
answer.code:51:47: error: expected ‘;’ before ‘)’ token
   51 |         ans1+=(1ll<<deep)*min(k-(cnt0>0),cnt1));
      |                                               ^
      |                                               ;