QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471388 | #1436. Split in Sets | bai_hong | WA | 1ms | 3964kb | C++14 | 1.9kb | 2024-07-10 20:52:37 | 2024-07-10 20:52:38 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define vint vector<int>
#define Pii pair<int,int>
const int mod=1e9+7;
const int QWQ=1e5+5;
using namespace std;
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())
if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())
x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
int fac[QWQ],inv[QWQ];
int n,K; vint a,A,B;
inline int kkk(int a,int b){
int ret=1;
for (;b;b>>=1,a=a*a%mod)
if (b&1) ret=ret*a%mod;
return ret;
}
inline void init(int N){
fac[0]=1;
for (int i=1;i<=N;i++)
fac[i]=fac[i-1]*i%mod;
inv[N]=kkk(fac[N],mod-2);
for (int i=N;i>=1;i--)
inv[i-1]=inv[i]*i%mod;
}
inline int C(int n,int m){
if (n<m) return 0;
return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int get(vint a,int len){
int ret=a[0];
for (int i=1;i<len;i++)
ret&=a[i];
return ret;
}
int sum(vint a){
int ret=0;
for (int u:a) ret+=u;
return ret;
}
Pii work(vint a,int k){
// for (int u:a) printf("%d ",u); puts("");
int h=-1; A.clear(),B.clear();
for (int u:a) if (u) h=max(h,__lg(u));
if (!~h){
int ret=0;
for (int i=0;i<=k;i++){
int val=C(k,i)*kkk(i,n)%mod;
ret=(ret+((k-i)&1 ? mod-val:val))%mod;
}
return {0,ret};
}
for (int u:a)
if (u>=1<<h) A.push_back(u);
else B.push_back(u);
int sA=A.size(),sB=B.size();
if (sA==a.size()){
for (int &u:A) u-=1<<h; Pii ret=work(A,k);
return {ret.first+k*(1<<h),ret.second};
}
if (sA>=k){
for (int &u:A) u-=1<<h;
int g=get(B,sB); A.push_back(g);
Pii ret=work(A,k);
return {ret.first+(k-1)*(1<<h),ret.second};
}
int g=sum(A); Pii ret=work(B,k-sA);
return {ret.first+g,ret.second*C(k,sA)%mod*fac[sA]%mod};
}
signed main(){
n=read(),K=read(),init(n);
for (int i=1,x;i<=n;i++)
a.push_back(x=read());
Pii ret=work(a,K);
printf("%lld %lld",ret.first,ret.second);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3864kb
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 157992351
result:
wrong answer 2nd words differ - expected: '671056390', found: '157992351'