QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791298 | #9572. Bingo | wildfire032 | WA | 146ms | 28404kb | C++20 | 2.7kb | 2024-11-28 17:56:25 | 2024-11-28 17:56:25 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repd(i,l,r) for(int i=l;i>=r;--i)
using namespace std;
using ll =long long;
using LL =long long;
const int N=1e6+50;
const int mod=998244353;
#define int long long
#define pb push_back
LL getmi(LL a,LL x)
{
LL rt=1;
while(x)
{
if(x&1) rt=rt*a%mod;
a=a*a%mod,x>>=1;
}
return rt;
}
int n,m,len,bin[N];
ll t[N];
LL lim,a[N],b[N],c[N],G[N],A0[N],A[N],B[N],inv[N];
ll f[N],F[N],g[N],h[N];
int getint()
{
char ch;
while(!isdigit(ch=getchar()));
int x=ch-48;
while(isdigit(ch=getchar())) x=x*10+ch-48;
return x;
}
void FFT(LL a[],int len,int tp)
{
rep(i,0,len-1) bin[i]=bin[i>>1]>>1|((i&1)*(len>>1));
rep(i,0,len-1) if(i<bin[i]) swap(a[i],a[bin[i]]);
for(int i=1; i<len; i<<=1)
{
LL wn=getmi(3,(mod-1)/(i<<1));
if(tp==-1) wn=getmi(wn,mod-2);
for(int j=0; j<len; j+=i<<1)
{
LL w=1,x,y;
rep(k,0,i-1)
{
x=a[j+k],y=a[i+j+k]*w%mod,w=w*wn%mod;
a[j+k]=(x+y)%mod,a[i+j+k]=(x-y+mod)%mod;
}
}
}
if(tp==-1)
{
LL x=getmi(len,mod-2);
rep(i,0,len-1) a[i]=a[i]*x%mod;
}
}
ll invv(ll x)
{
return getmi(x,mod-2);
}
ll fac[N],ifac[N];
void init(ll nn=N-5)
{
fac[0]=fac[1]=ifac[0]=ifac[1]=1;
rep(i,2,nn) fac[i]=fac[i-1]*i%mod;
ifac[nn]=invv(fac[nn]);
repd(i,nn,2) ifac[i-1]=ifac[i]*i%mod;
}
ll C(ll n,ll m)
{
return fac[n]*ifac[m]*ifac[n-m]%mod;
}
void solve()
{
cin>>n>>m;
rep(i,1,n*m) cin>>t[i];
//cout<<ifac[0]<<"\n";
sort(t+1,t+n*m+1);
ll len=1;
for(len=1;len<=2*n*m;len<<=1);
len<<=1;
rep(i,0,len<<1)g[i]=f[i]=h[i]=0;
g[0]=0;
rep(i,1,m*n)g[i]=t[i]*fac[i-1]%mod;
//rep(i,1,n*m)g[i]=1;
// rep(i,n*m+1,2*n*m)g[i]=0;
rep(i,0,m*n)h[i]=ifac[n*m-i];
//rep(i,n*m+1,2*n*m)h[i]=0;
rep(i,1,len)f[i]=0;
//rep(i,1,2*m*n) cout<<i<<" "<<g[i]<<"\n";
FFT(g,len,1);FFT(h,len,1);
rep(i,0,len) f[i]=1LL*g[i]*h[i]%mod;
FFT(f,len,-1);
rep(i,0,n*m)F[i]=f[n*m+i];
//rep(i,1,2*m*n) cout<<i<<" "<<f[i]<<"\n";
ll ans=0;
rep(c,0,n) rep(d,0,m)
{
ll k=n*m-d*c,tmp=0;
tmp=C(n,c)*C(m,d)%mod;
tmp=tmp*fac[n*m-k]%mod*(k)%mod;
tmp=tmp*F[k]%mod;
if((n+m-c-d)%2) ans=(ans+tmp)%mod;
else ans=(ans+mod-tmp)%mod;
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t=1;
init();
cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 28140kb
input:
4 2 2 1 3 2 4 3 1 10 10 10 1 3 20 10 30 3 4 1 1 4 5 1 4 1 9 1 9 8 10
output:
56 60 60 855346687
result:
ok 4 number(s): "56 60 60 855346687"
Test #2:
score: 0
Accepted
time: 8ms
memory: 27516kb
input:
1 2 2 0 0 998244352 998244352
output:
998244345
result:
ok 1 number(s): "998244345"
Test #3:
score: -100
Wrong Answer
time: 146ms
memory: 28404kb
input:
900 1 1 810487041 1 2 569006976 247513378 1 3 424212910 256484544 661426830 1 4 701056586 563296095 702740883 723333858 1 5 725786515 738465053 821758167 170452477 34260723 1 6 204184507 619884535 208921865 898995024 768400582 369477346 1 7 225635227 321139203 724076812 439129905 405005469 369864252...
output:
810487041 495026756 540662911 541929691 534597815 525563893 35088017 39634422 525836140 399215295 597677927 259862138 480120394 101693809 364698461 67964433 703349355 419697197 471189075 171209526 355431284 642992452 308808960 694742957 353177443 667364143 637921478 644372014 123175866 302480005 641...
result:
wrong answer 5th numbers differ - expected: '118309348', found: '534597815'