QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470781 | #1436. Split in Sets | yqh2025 | WA | 1ms | 3852kb | C++14 | 1.7kb | 2024-07-10 16:24:49 | 2024-07-10 16:24:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10,mod=1e9+7;
int ksm(int x,int y){int ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}
int inv(int x){return ksm(x,mod-2);}
int n,k,a[N];
int bit(int x,int y){return (x>>y)&1;}
int jc[N],invjc[N];
void init(){
jc[0]=1;for(int i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;
invjc[n]=inv(jc[n]);
for(int i=n-1;i>=0;i--)invjc[i]=invjc[i+1]*(i+1)%mod;
}
int C(int n,int m){
if(n<m)return 0;
return jc[n]*invjc[m]%mod*invjc[n-m]%mod;
}
signed main(){
scanf("%lld%lld",&n,&k);
init();
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
int ans1=0,ans2=1;
for(int t=30;t>=0;t--){
int cnt=0;
for(int i=1;i<=n;i++)cnt+=bit(a[i],t);
if(!cnt){
if(t)continue;
int sum=0;
for(int i=0;i<=k;i++){
if((k-i)&1)sum=(sum-C(k,i)*ksm(i,n)%mod+mod)%mod;
else sum=(sum+C(k,i)*ksm(i,n)%mod)%mod;
}
ans2=ans2*sum%mod;
continue;
}
if(cnt<=k-1){
vector<int>ve;
for(int i=1;i<=n;i++)if(bit(a[i],t))ans1+=a[i];else ve.push_back(a[i]);
n=ve.size();for(int i=1;i<=n;i++)a[i]=ve[i-1];
ans2=ans2*jc[k]%mod*invjc[k-cnt]%mod;
k-=cnt;
}
else{
int x=-1;
for(int i=1;i<=n;i++)if(!bit(a[i],t)){
if(x==-1)x=a[i];else x&=a[i];
}
vector<int>ve;if(x!=-1)ve.push_back(x);
for(int i=1;i<=n;i++)if(bit(a[i],t))ve.push_back(a[i]^(1<<t));
n=ve.size();for(int i=1;i<=n;i++)a[i]=ve[i-1];
ans1+=(k-1)*(1<<t);
if(x==-1)ans1+=1<<t;
}
// cout<<t<<":\n";
// cout<<"n k:"<<n<<" "<<k<<endl;
// for(int i=1;i<=n;i++)cout<<a[i]<<" ";
// cout<<endl<<"ans1 ans2:"<<ans1<<" "<<ans2<<endl;
// cout<<endl;
}
printf("%lld %lld",ans1,ans2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3852kb
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'