QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519882 | #1436. Split in Sets | hanmm81 | WA | 1ms | 5800kb | C++14 | 1.1kb | 2024-08-15 09:01:25 | 2024-08-15 09:01:25 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,k,a[100005],inv[100005],jc[100005],where[100005],size,ans1,ans2=1,cn;
map<int,int> m;
map<int,int> cnt;
void dfs(int x,int y,int k){
if (x < 0 || k == 0 || y > n) return;
int cnt = 0,sum = 0;
for (;y <= n;y++){
if (a[y] >= (1ll<<x) && cnt != k-1) where[y] = ++cn,cnt++,sum += a[y];
else break;
}
ans1 += sum;
if (cnt != k-1) dfs(x-1,y,k-cnt);
else{
int andd = -1;
for (;y <= n;y++) m[a[y]]++,where[y] = k,andd = (andd == -1 ? a[y] : andd&a[y]);
if (andd != -1) ans1 += andd;
}
}
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 C(int x,int y){
return jc[x]*inv[x-y]%mod*inv[y]%mod;
}
signed main(){
cin >> n >> k,jc[0] = inv[0] = 1;
for (int i = 1;i <= n;i++) jc[i] = jc[i-1]*i%mod,inv[i] = ksm(jc[i],mod-2);
for (int i = 1;i <= n;i++) cin >> a[i],cnt[a[i]]++;
sort(a+1,a+n+1,[](int a,int b){return(a>b);});
dfs(31,1,k);
for (auto i : m) ans2 = ans2*C(cnt[i.first],i.second)%mod;
cout << ans1 << " " << ans2*jc[k]%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5748kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 1ms
memory: 5676kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5800kb
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'