QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520176 | #1436. Split in Sets | cqzhm | WA | 2ms | 5276kb | C++14 | 1.4kb | 2024-08-15 11:20:02 | 2024-08-15 11:20:02 |
Judging History
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<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5204kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 2ms
memory: 5152kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 2ms
memory: 5212kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 5276kb
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 -152712092
result:
wrong answer 2nd words differ - expected: '671056390', found: '-152712092'