QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#802453 | #8150. XOR Sum | Maxduan# | WA | 3ms | 6172kb | C++23 | 3.0kb | 2024-12-07 13:44:04 | 2024-12-07 13:44:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100005
const int p=1e9+7;
int dp[70][1<<7][20];
int N[70],M[70];
int ok[101];
vector<int>h[1<<7];
int fac[maxn],inv[maxn];
int qpow(int a,int b){
int ans=1;
int tmp=a;
while(b){
if(b&1){
ans=ans*tmp%p;
}
tmp=tmp*tmp%p;
b>>=1;
}
return ans;
}
int C(int a,int b){
if (a < b) return 0;
return fac[a]*inv[b]%p*inv[a-b]%p;
}
void solve(){
int n,m,k;cin>>n>>m>>k;
memset(ok,-1,sizeof(ok));
for(int i=0;i<=k/2;i++){
ok[i*(k-i)]=i;
}
for(int i=60;i>=0;i--){
N[i]=(n>>i&1);
M[i]=(m>>i&1);
}
dp[60][0][k]=1;
for(int i=0;i<(1<<7);i++){
for(int j=0;j<(1<<7);j++){
if((j|i)==j){
h[i].push_back(j);
}
}
}
int ans=0;
for(int i=60;i>=0;i--){
for(int v=0;v<(1<<7);v++){
int tmp=0;
for(int u=0;u<7;u++){
if(v>>u&1){
tmp+=(1<<u);
}
}
if(ok[tmp]==-1)continue;
for(int cnt=0;cnt<=k;cnt++){
for(auto u:h[v]){
if(dp[i][u][cnt]==0)continue;
int nxt=((u^v)<<1)+(i>0?N[i-1]:0);
if(nxt>=(1<<7))continue;
for(int cnt2=0;cnt2<=cnt;cnt2++){
if(M[i]==0&&cnt2!=cnt)continue;
int x=ok[tmp],y=k-ok[tmp];//0 1
if(cnt-cnt2<=y){
int tp=C(k-cnt,y-cnt+cnt2)*C(cnt,cnt2)%p;
if(i>0){
dp[i-1][nxt][cnt2]+=dp[i][u][cnt]*tp%p;
if(dp[i-1][nxt][cnt2]>=p)dp[i-1][nxt][cnt2]-=p;
}
else if(nxt==0){
ans+=dp[i][u][cnt]*tp%p;
}
}
swap(x,y);
if(cnt-cnt2<=y&&x!=y){
int tp=C(k-cnt,y-cnt+cnt2)*C(cnt,cnt2)%p;
if(i>0){
dp[i-1][nxt][cnt2]+=dp[i][u][cnt]*tp%p;
if(dp[i-1][nxt][cnt2]>=p)dp[i-1][nxt][cnt2]-=p;
}
else if(nxt==0){
ans+=dp[i][u][cnt]*tp%p;
}
}
}
}
}
}
}
cout<<ans%p;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
fac[0]=1;
for(int i=1;i<maxn;i++){
fac[i]=fac[i-1]*i%p;
}
inv[maxn-1]=qpow(fac[maxn-1],p-2);
for(int i=maxn-2;i>=0;i--){
inv[i]=inv[i+1]*(i+1)%p;
}
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5432kb
input:
6 2 3
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5512kb
input:
30 6 5
output:
1520
result:
ok 1 number(s): "1520"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5424kb
input:
0 0 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5556kb
input:
0 0 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5508kb
input:
0 1145141919 2
output:
145141913
result:
ok 1 number(s): "145141913"
Test #6:
score: 0
Accepted
time: 3ms
memory: 5560kb
input:
0 0 18
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 6012kb
input:
0 12412414 18
output:
12412415
result:
ok 1 number(s): "12412415"
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 6172kb
input:
32071009996106 682053093123 12
output:
0
result:
wrong answer 1st numbers differ - expected: '443207413', found: '0'