QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470914 | #1436. Split in Sets | sumi007 | WA | 1ms | 9944kb | C++14 | 1.5kb | 2024-07-10 16:54:26 | 2024-07-10 16:54:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 5e5+5,mod = 1e9+7;
ll n,m,a[N],b[N],fac[N],inv[N];
ll qpow(ll a,ll p){
ll res = 1;
for(;p;p>>=1,a=a*a%mod) if(p&1) res = res*a%mod;
return res;
}
ll C(ll n,ll m){
return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
cin.tie(0),cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i];
fac[0] = 1;
for(int i=1;i<=m;i++) fac[i] = fac[i-1]*i%mod;
inv[m] = qpow(fac[m],mod-2);
for(int i=m-1;i>=0;i--) inv[i] = inv[i+1]*(i+1)%mod;
sort(a+1,a+1+n);
ll L = log2(a[n]),ans = 0,tot = 1;
for(int k=L;k>=0;k--){
ll cnt = 0;
for(int i=1;i<=n;i++) if(a[i]&(1<<k)) cnt++;
if(!cnt) continue;
if(cnt == n){
ans += (1ll<<k)*m;
for(int i=1;i<=n;i++) a[i] -= (1<<k);
continue;
}
if(cnt >= m){
ans += (1ll<<k)*(m-1);
ll t = 0,val = (1<<(L+1))-1;
for(int i=1;i<=n;i++) {
if(a[i]&(1<<k)) continue;
val &= a[i];
}
for(int i=1;i<=n;i++){
if(a[i]&(1<<k)) b[++t] = a[i]-(1<<k);
}
b[++t] = val,n = t;
for(int i=1;i<=n;i++) a[i] = b[i];
}else{
for(int i=1;i<=n;i++) if(a[i]&(1<<k)) ans += a[i];
tot = tot*C(m,cnt)%mod*fac[cnt]%mod,m -= cnt;
int t = 0;
for(int i=1;i<=n;i++){
if(a[i]&(1<<k)) continue;
b[++t] = a[i];
}
n = t;
for(int i=1;i<=n;i++) a[i] = b[i];
}
}
if(n && m && n>=m) tot = tot*C(n-1,m-1)%mod*fac[m]%mod;
cout << ans << ' ' << tot << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9884kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 1ms
memory: 9944kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 1ms
memory: 9864kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 9736kb
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 198463938
result:
wrong answer 2nd words differ - expected: '671056390', found: '198463938'