QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521011 | #1436. Split in Sets | c20251515 | WA | 8ms | 20956kb | C++14 | 1.7kb | 2024-08-15 19:51:07 | 2024-08-15 19:51:08 |
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){
assert(k <= s.size());
ll cnt0 = 0,cnt1 = 0;
for(auto i : s) if((i >> deep) & 1) ++cnt1; else ++cnt0;
ans1 += min(k - (cnt0 > 0),cnt1) * (1ll << deep);
if(deep == 0) {
if(k > cnt1) ans2 = 1ll * ans2 * strling(cnt0,k - cnt1) % mod;
else ans2 = 1ll * ans2 * strling(1 + cnt1,k) % 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: 100
Accepted
time: 8ms
memory: 20388kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 8ms
memory: 20956kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 7ms
memory: 20004kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 7ms
memory: 20348kb
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:
467198368 671056390
result:
wrong answer 1st words differ - expected: '35467198613', found: '467198368'