QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520638 | #1436. Split in Sets | 123456xwd | WA | 0ms | 3852kb | C++14 | 1.7kb | 2024-08-15 14:27:09 | 2024-08-15 14:27:09 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pli pair<ll,int>
using namespace std;
const int N=1e5+5,MOD=1e9+7;
int n,k,a[N],b[N];
int jc[N],invf[N];
int power(int x,int y){
int ans=1;
for(;y;y>>=1,x=1ll*x*x%MOD) if(y&1) ans=1ll*ans*x%MOD;
return ans;
}
int A(int n,int m){ return 1ll*jc[n]*invf[n-m]%MOD; }
int C(int n,int m){ return 1ll*jc[n]*invf[n-m]%MOD*invf[m]%MOD; }
void add(int &x,int y){ x+=y; if(x>=MOD) x-=MOD; if(x<0) x+=MOD; }
pli dfs(int d,int n,int k){
if(d<0){
int ans=0;
for(int i=0;i<k;++i) add(ans,(((k-i)&1)?-1ll:1ll)*power(i,n)%MOD*C(k,i)%MOD);
return {0,ans};
}
int cnt=0;
for(int i=1;i<=n;++i) cnt+=(a[i]>>d&1);
if(!cnt) return dfs(d-1,n,k);
if(cnt==n){
for(int i=1;i<=n;++i) a[i]-=(1<<d);
auto ans=dfs(d-1,n,k);
return {ans.first+1ll*(1<<d)*k,ans.second};
}
if(cnt<k){
ll sum=0;
for(int i=1,j=0;i<=n;++i){
if(a[i]<(1<<d)) a[++j]=a[i];
else sum+=a[i];
}
auto ans=dfs(d-1,n-cnt,k-cnt);
return {ans.first+sum,1ll*ans.second*A(k,cnt)%MOD};
}
int now=(1<<30)-1,j=0;
for(int i=1;i<=n;++i){
if(a[i]>=(1<<d)) a[i]-=(1<<d),a[++j]=a[i];
else now&=a[i];
}
a[++j]=now;
auto ans=dfs(d-1,j,k);
return {ans.first+1ll*(1<<d)*(k-1),ans.second};
}
int main(){
scanf("%d%d",&n,&k);
jc[0]=1; for(int i=1;i<=n;++i) jc[i]=1ll*jc[i-1]*i%MOD;
invf[n]=power(jc[n],MOD-2);
for(int i=n-1;~i;--i) invf[i]=1ll*invf[i+1]*(i+1)%MOD;
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
auto ans=dfs(29,n,k);
printf("%lld %d\n",ans.first,ans.second);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3852kb
input:
3 2 4 7 5
output:
11 0
result:
wrong answer 2nd words differ - expected: '2', found: '0'