QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509526 | #1436. Split in Sets | xiahaob | WA | 1ms | 4132kb | C++14 | 2.0kb | 2024-08-08 15:40:48 | 2024-08-08 15:40:48 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define pb(a) push_back(a)
using namespace std;
inline int rd(){
int s=0,w=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
return s*w;
}
const int p=1e9+7,N=1e5+5;
int n,num,ans1,ans2=1;
int fac[N],inv[N];
vector<int> a,b;
inline int qpow(int A,int B){
int sm=1;for(;B;B>>=1,A=(A*A)%p)if(B&1)sm=(sm*A)%p;
return sm;
}
inline void add(int &x,int y){x+=y;if(x>=p)x-=p;}
inline void del(int &x,int y){x-=y;if(x<0)x+=p;}
inline int C(int A,int B){
if(A<B||B<0)return 0;
return fac[A]*inv[A-B]%p*inv[B]%p;
}
inline int A(int x,int y){
if(x<y||y<0)return 0;
return fac[x]*inv[x-y]%p;
}
inline int work(int A,int B){
int sm=0;
for(int i=0;i<=B;++i){
if(i&1)del(sm,qpow(B-i,A)*C(B,B-i)%p);
else add(sm,qpow(B-i,A)*C(B,B-i)%p);
}
return sm;
}
inline void solve(int bit,int k,vector<int> now){
n=now.size();
if(bit==-1){
ans2=(ans2*work(n,k))%p;
return;
}
a.clear();b.clear();
for(int v:now){
if((v>>bit)&1)a.pb(v);
else b.pb(v);
}
// printf("a:");
// for(int v:a)printf("%d ",v);
// puts("");
// printf("b:");
// for(int v:b)printf("%d ",v);
int x=a.size();
if(x<k){//
int sum=0;
for(int v:a)sum=(sum+v)%p;
ans1=ans1+sum;ans2=ans2*A(k,x)%p;
solve(bit-1,k-x,b);
}
else{
if(x==n){
ans1=ans1+k*(1<<bit);
b.clear();for(int v:a)b.pb(v-(1<<bit));
solve(bit-1,k,b);
}
else{
int special=INT_MAX;
for(int v:b)special&=v;
b.clear();
for(int v:a)b.pb(v-(1<<bit));
b.pb(special);ans1=ans1+(k-1)*(1<<bit);
solve(bit-1,k,b);
}
}
}
// long long
signed main(){
n=rd();num=rd();
fac[0]=1;inv[0]=1;
rep(i,1,num)fac[i]=fac[i-1]*i%p,inv[i]=qpow(fac[i],p-2);
rep(i,1,n){int x=rd();a.pb(x);}
solve(30,num,a);
printf("%lld %lld",ans1,ans2);
return 0;
}
/*
3 2
4 7 5
*/
/*
4 1
44 47 74 77
*/
/*
4 4
44 47 74 77
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4004kb
input:
3 2 4 7 5
output:
11 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
4 1 44 47 74 77
output:
8 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
4 4 44 47 74 77
output:
242 24
result:
ok 2 tokens
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 4132kb
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:
4467198396 671056390
result:
wrong answer 1st words differ - expected: '35467198613', found: '4467198396'