QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472548 | #1436. Split in Sets | SunsetLake | WA | 1ms | 3824kb | C++14 | 2.0kb | 2024-07-11 17:07:03 | 2024-07-11 17:07:04 |
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: 100
Accepted
time: 0ms
memory: 3764kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3772kb
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 538628446
result:
wrong answer 2nd words differ - expected: '671056390', found: '538628446'