QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521007 | #1436. Split in Sets | c20251515 | WA | 8ms | 20512kb | C++14 | 1.7kb | 2024-08-15 19:47:49 | 2024-08-15 19:47:49 |
Judging History
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 i : s) if((i >> deep) & 1) ++cnt1; else ++cnt0;
ans1 += min(k - (cnt0 > 0),cnt1) * (1ll << deep);
ans1=(ans1+(1ll<<deep)*min(k-(cnt0>0),cnt1))%mod;
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
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 20512kb
input:
3 2 4 7 5
output:
21 2
result:
wrong answer 1st words differ - expected: '11', found: '21'