QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472547 | #1436. Split in Sets | SunsetLake | WA | 0ms | 3808kb | C++14 | 2.0kb | 2024-07-11 17:06:27 | 2024-07-11 17:06:28 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N = 1e5 + 5,mod = 1e9 + 7;
int n,k;
ll fac[N],inv[N],sum,cnt;
ll qpow(ll x,ll y){
ll res = 1;
while(y){
if(y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
ll C(ll x,ll y){
if(x < y || x < 0 || y < 0) return 0;
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
ll calc(ll x,ll y){//x diff balls --> y same boxes can't empty
ll res = 0;
for(int i = 0;i <= y;++ i)
if(i & 1) res = (res - C(y,i) * qpow(y - i,x) % mod + mod) % mod;
else res = (res + C(y,i) * qpow(y - i,x) % mod) % mod;
return res;
}
vector<int>v,tmp;
void print(){
for(auto now : tmp) cout << now << " ";
puts("");
}
int main(){
cin >> n >> k;
int ppp = k;
for(int i = 1,a;i <= n;++ i) scanf("%d",&a),v.pb(a);
fac[0] = inv[0] = 1;
for(int i = 1;i <= n;++ i) fac[i] = fac[i - 1] * i % mod;
inv[n] = qpow(fac[n],mod - 2);
for(int i = n - 1;i >= 1;-- i) inv[i] = inv[i + 1] * (i + 1) % mod;
while(1){
ll mx = 0;
for(auto now : v) mx = max(mx,1ll * now);
if(!mx) break;
ll bit = __lg(mx);
mx = 1 << bit;
int num = 0;
for(auto now : v) num += (now >= mx);
if(mx == 1){
puts("gfdhdhgf");
if(num < k) cnt = (cnt + calc(v.size() - num,k - num)) % mod;
else cnt = (cnt + calc(num + 1,k)) % mod;
}
if(num < k){
for(auto now : v) if(now >= mx) sum += now;
k -= num;
for(auto now : v) if(now < mx) tmp.pb(now);
}
else{
if(num == v.size()){
sum += k * mx;
for(auto now : v) tmp.pb(now ^ mx);
// cout << "fdsgsg\n";
// print();
}
else{
sum += (k - 1) * mx;
int kk = (1 << 30) - 1;
for(auto now : v)
if(now < mx) kk &= now;
else tmp.pb(now ^ mx);
tmp.pb(kk);
}
}
swap(v,tmp);
tmp.clear();
}
if(!cnt) cnt = 1;
cout << sum << " " << cnt * fac[ppp] % mod;
return 0;
}
/*
3 2
4 7 5
100
111
101
4 1
44 47 74 77
0101100
0101111
1001010
1001101
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3808kb
input:
3 2 4 7 5
output:
gfdhdhgf 11 2
result:
wrong answer 1st words differ - expected: '11', found: 'gfdhdhgf'