QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470732 | #1436. Split in Sets | hyxle | WA | 1ms | 5680kb | C++20 | 2.7kb | 2024-07-10 16:06:04 | 2024-07-10 16:06:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N=1e5+5,mod=1e9+7;
ll n,k,a[N],res1,res2=1,mul[N],inv[N];
vector<int> v;
inline ll qmul(ll a,ll b){
ll ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=(a*a)%mod;b>>=1;
}
return ans;
}
inline void init(int _n){
inv[0]=mul[0]=1;
for(R int i=1;i<=_n;++i)mul[i]=mul[i-1]*i%mod;
inv[_n]=qmul(mul[_n],mod-2);
for(R int i=_n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%mod;
}
inline ll C(ll a,ll b){
if(a<b||b<0||a<0)return 0;
return mul[a]*inv[b]%mod*inv[a-b]%mod;
}
inline void solve(int len,int cntk,int t){
if(t<0||!len)return;
if(cntk==1){
int res=v[0];
for(R int i=1;i<len;++i)res&=v[i];
res1+=res;
return;
}
// cout<<len<<' '<<cntk<<'\n';
vector<int> v1;int cnt=0;
for(R int i=0;i<len;++i){
v1.push_back(v.back());int kk=v.back();v.pop_back();
if((kk>>t)&1)++cnt;
}
if(!cnt){
for(R int i=0;i<len;++i){
v.push_back(v1.back());v1.pop_back();
}
solve(len,cntk,t-1);
return;
}
if(cnt<cntk){
res2=(res2*mul[cntk]%mod*inv[cntk-cnt])%mod;
for(R int i=0;i<len;++i){
int kk=v1.back();v1.pop_back();
if((kk>>t)&1){
res1+=kk;
// cout<<kk<<' ';
}
else v.emplace_back(kk);
}
solve(v.size(),cntk-cnt,t-1);
}else if(cnt==cntk){
for(R int i=0;i<len;++i){
res1+=v1[i];
// cout<<v1[i]<<' ';
}
res2=res2*mul[cntk]%mod*inv[cntk-cnt]%mod;
cout<<res1<<' '<<res2;exit(0);
}else if(cnt==len&&cnt>cntk){
res1+=(1<<t)*(cntk);
for(R int i=0;i<len;++i){
int kk=v1.back();
if((kk>>t)&1){
kk^=(1<<t);
v.push_back(kk);
}
v1.pop_back();
}
solve(v.size(),cntk,t-1);
}else{
res1+=(1<<t)*(cntk-1);
int res=0;bool fl=0;
for(R int i=0;i<len;++i){
int kk=v1.back();
if((kk>>t)&1){
kk^=(1<<t);
v.push_back(kk);
}else{
if(!fl)fl=1,res=kk;
else res&=kk;
}
v1.pop_back();
}
v.push_back(res);
solve(v.size(),cntk,t-1);
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n>>k;init(max(n,k));
for(R int i=1;i<=n;++i)cin>>a[i],v.emplace_back(a[i]);
solve(n,k,30);
cout<<res1<<' '<<res2<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3760kb
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'