QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581971 | #9380. Match | Mo_Han136 | AC ✓ | 148ms | 20080kb | C++20 | 2.6kb | 2024-09-22 14:47:55 | 2024-09-22 14:47:56 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)
using namespace std;
const int N=205,M=1e6+5,P=998244353;
int MOD(int x){
if(x>=P)x-=P;
if(x<0)x+=P;
return x;
}
void ADD(int &x,int y){
x=MOD(x+y);
}
int n;
LL k,a[N],b[N];
int son[M][2],tot,sz[M],rt1,rt2;
int s[M],ks[M];
void add(LL x,int p){
rep(i,0,59){
s[i]=x&1;
x>>=1;
}
drep(i,59,0){
if(!son[p][s[i]])son[p][s[i]]=++tot;
++sz[p=son[p][s[i]]];
}
}
int C[N][N],A[N][N];
int f[M][N];
int tmp[N];
void dfs(int p,int q,int t){
if(!p || !q){
f[p][0]=1;
return;
}
// printf("dfs %d %d %d\n",p,q,t);
if(t<0){
rep(i,0,min(sz[p],sz[q]))f[p][i]=1ll*C[sz[p]][i]*A[sz[q]][i]%P;
return;
}
if(ks[t]==1){
dfs(son[p][0],son[q][1],t-1);
dfs(son[p][1],son[q][0],t-1);
rep(i,0,min(sz[son[p][0]],sz[son[q][1]]))if(f[son[p][0]][i])
rep(j,0,min(sz[son[p][1]],sz[son[q][0]]))if(f[son[p][1]][j])
ADD(f[p][i+j],1ll*f[son[p][0]][i]*f[son[p][1]][j]%P);
return;
}
dfs(son[p][0],son[q][0],t-1);
dfs(son[p][1],son[q][1],t-1);
rep(i,0,min(sz[son[p][0]],sz[son[q][0]]))if(f[son[p][0]][i])
rep(j,0,min(sz[son[p][1]],sz[son[q][1]]))if(f[son[p][1]][j]){
int sp0=sz[son[p][0]]-i;
int sq0=sz[son[q][0]]-i;
int sp1=sz[son[p][1]]-j;
int sq1=sz[son[q][1]]-j;
int s=min(sp0,sq1)+min(sp1,sq0);
rep(k,0,s)tmp[k]=0;
rep(u,0,min(sp0,sq1))rep(v,0,min(sp1,sq0))
ADD(tmp[u+v],1ll*C[sp0][u]*A[sq1][u]%P*C[sp1][v]%P*A[sq0][v]%P);
rep(k,0,s)ADD(f[p][i+j+k],1ll*f[son[p][0]][i]*f[son[p][1]][j]%P*tmp[k]%P);
}
}
void init(){
rep(i,C[0][0]=1,n)rep(j,C[i][0]=1,i)
C[i][j]=MOD(C[i-1][j-1]+C[i-1][j]);
rep(i,A[0][0]=1,n)rep(j,A[i][0]=1,i)
A[i][j]=1ll*A[i][j-1]*(i-j+1)%P;
}
int main(){
scanf("%d%lld",&n,&k);
LL x=k;
rep(i,0,59){
ks[i]=x&1;
x>>=1;
}
rep(i,1,n)scanf("%lld",&a[i]);
rep(i,1,n)scanf("%lld",&b[i]);
rt1=++tot;
rep(i,1,n)add(a[i],rt1);
rt2=++tot;
rep(i,1,n)add(b[i],rt2);
init();
dfs(rt1,rt2,59);
rep(i,1,n)printf("%d\n",f[rt1][i]);
return 0;
}
/*
9 5
1 7 2 8 4 9 2 5 10
1 3 2 4 5 8 8 8 9
51
1034
10768
62195
200965
348924
294444
97344
7200
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9972kb
input:
9 5 1 7 2 8 4 9 2 5 10 1 3 2 4 5 8 8 8 9
output:
51 1034 10768 62195 200965 348924 294444 97344 7200
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 148ms
memory: 20080kb
input:
200 569102225177443347 1103663383682482176 1103381908705771520 1099441259031822336 1098878309078401024 1089871109823660032 1080863910568919040 1074108511127863296 1071856711314178048 1069041961547071488 1068479011593650176 1067353111686807552 1062849512059437056 1049338713177325568 10448351135499550...
output:
20506 208107723 47878304 53020813 972282728 933586852 658157196 670189811 957980024 366179738 217980591 967482558 833450149 987731802 260904367 5263881 600332344 906061351 658256294 93700706 421323952 178075016 219871690 986880524 848776106 191185484 641917326 576497440 908609746 349728876 606714342...
result:
ok 200 lines
Test #3:
score: 0
Accepted
time: 11ms
memory: 18912kb
input:
200 1098723432450995412 972777519512027136 936748722493063168 864691128455135232 860187528827764736 857935729014079488 856246879153815552 855683929200394240 851180329573023744 848928529759338496 847802629852495872 847310048643252224 847239679899074560 846676729945653248 828662331436171264 8280993814...
output:
8320 34035512 428014253 916072411 696504298 748377440 32424677 188402417 233587075 130639672 759476380 546285625 187068736 159002787 131866334 381530906 133126344 373727612 923311054 725293681 718162548 39511135 322320638 44709653 156884882 285926751 787179409 282967016 153092344 615721347 950855850...
result:
ok 200 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 10124kb
input:
200 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
3072 4412928 940025853 665370743 752672705 581549490 41990996 541401698 170451802 26584141 220983766 844620126 64506869 137621326 418866920 351049174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 200 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 12132kb
input:
200 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
40000 792020000 319908096 286630939 515085548 95626140 472749362 800008042 594973486 139901984 847967250 125664877 254232250 419486325 204481923 979660340 41873095 540955890 585129047 205968776 196086667 674391130 737319172 669580034 973843015 207125612 331414909 119844754 24879477 990932807 8476927...
result:
ok 200 lines
Extra Test:
score: 0
Extra Test Passed