QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472393 | #1436. Split in Sets | zbrc | WA | 199ms | 39692kb | C++14 | 1.7kb | 2024-07-11 16:09:40 | 2024-07-11 16:09:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+10,mod=1e9+7;
int n,k,ans;
multiset<int>a;
int inv[N],fac[N];
int Pow(int x,int n){
if(n==0)return 1;
int a=Pow(x,n/2);
return a*a%mod*(n&1?x:1)%mod;
}
void init(){
inv[0]=fac[0]=1;
for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
inv[N-1]=Pow(fac[N-1],mod-2);
for(int i=N-2;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
int P(int n,int m){
return fac[n]*inv[n-m]%mod;
}
int C(int n,int m){
if(m<0)return 0;
int res=0;
for(int i=0;i<=m;i++){
if((m-i)&1)res=(res+mod-Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
else res=(res+Pow(i,n)*inv[i]%mod*inv[m-i]%mod)%mod;
}
return res;
}
int tot=1;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>k;
init();
tot=tot*P(k,k);
for(int i=1;i<=n;i++){
int x;cin>>x;
a.insert(x);
}
if(k==1){
ans=*a.begin();
for(auto i : a)ans&=i;
cout<<ans<<' '<<1;
return 0;
}
vector<int>e;
for(int i=30;i>=0&&k;i--){
int cnt=0;
e.clear();
for(auto j : a){
if((j>>i)&1){
cnt++;
e.push_back(j);
}
}
if(i==0){
if(cnt<k)tot=tot*C(a.size()-cnt,k-cnt)%mod;
else tot=C(cnt+1,k)*tot%mod;
}
if(cnt==a.size())ans+=min(k,cnt)*(1LL<<i);
else ans+=min((k-1),cnt)*(1LL<<i);
if(cnt<k){
k-=cnt;
for(int j=0;j<e.size();j++){
ans+=e[j]&((1LL<<i)-1);
a.erase(a.lower_bound(e[j]));
}
}else{
int s=0,flag=1;
for(auto j = a.rbegin();j != a.rend();j++){
if(lower_bound(e.begin(),e.end(),*j)==e.end()){
if(flag)s=*j,flag=0;
else s&=*j;
a.erase(a.lower_bound(*j));
}
}
if(cnt!=a.size())a.insert(s);
}
}
cout<<ans<<' '<<tot<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 35040kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 19ms
memory: 34852kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 20ms
memory: 35036kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: 0
Accepted
time: 16ms
memory: 34832kb
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 671056390
result:
ok 2 tokens
Test #5:
score: -100
Wrong Answer
time: 199ms
memory: 39692kb
input:
99988 19981 11771832 114 110908254 348 553453 840525742 342620766 12408 27914 2 29 4914992 79461083 133 0 44575 11059027 13445407 3508312 227 50410231 1253800 12277 201525297 39 88 20236754 417742 0 8412502 172886086 35315 144742219 211319 352393 10445 1330114 56814394 90807971 3 69704 104497 0 9176...
output:
3435081668397 264671051
result:
wrong answer 1st words differ - expected: '3435071736287', found: '3435081668397'