QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720868#9572. Bingoucup-team902#WA 49ms22076kbC++172.8kb2024-11-07 14:31:512024-11-07 14:31:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 14:31:57]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:22076kb
  • [2024-11-07 14:31:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1<<19;
const int mod=998244353;
using arr=int[N+5];
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int red(int &x){ return x+=(x>>31)&mod; }
int ksm(ll x,int tp,int s=1){
    for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
    return s;
}
int fac[N+5],ifac[N+5];
void prep(){
    fac[0]=1;
    for(int i=1;i<=N;i++) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[N]=ksm(fac[N],mod-2);
    for(int i=N;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m){ return n<0||m<0||n<m?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; }
namespace poly{
    int L,iv;
    arr w,rev;
    arr pa,pb;
    #define szf sizeof(int)
    void cl(arr a){ memset(a,0,L*szf); }
    void r_prep(){
        int L=N>>1;
        int val=ksm(3,(mod-1)/N);
        w[L]=1;
        for(int i=1;i<L;i++) w[i+L]=1ll*w[i+L-1]*val%mod;
        for(int i=L-1;i;i--) w[i]=w[i<<1];
    }
    void pre_n(int n){
        L=1; while(L<n) L<<=1;
        iv=mod-(mod-1)/L;
        for(int i=1;i<L;i++) rev[i]=(rev[i>>1]>>1)|(i&1?L>>1:0);
    }
    void FFT(arr t,bool ok=1){
        int x,y;
        for(int i=1;i<L;i++)
            if(i<rev[i]) swap(t[i],t[rev[i]]);
        for(int i=1;i<L;i<<=1)
            for(int j=0;j<L;j+=i<<1)
                for(int l=0;l<i;l++){
                    x=t[j+l]; y=1ll*t[i+j+l]*w[i+l]%mod;
                    t[i+j+l]=sub(x,y); t[j+l]=add(x,y);
                }
        if(!ok){
            reverse(t+1,t+L);
            for(int i=0;i<L;i++) t[i]=1ll*t[i]*iv%mod;
        }
    }
    void NTT(arr a){ FFT(a); }
    void INTT(arr a){ FFT(a,0); }
    void NTT(arr a,arr b){ memcpy(b,a,L*szf); FFT(b); }
    void INTT(arr a,arr b){ memcpy(b,a,L*szf); FFT(b,0); }
    void Mult(arr a,arr b,arr c,int n){
        pre_n(n);
        NTT(a,pa); NTT(b,pb);
        for(int i=0;i<L;i++)
            c[i]=1ll*pa[i]*pb[i]%mod;
        INTT(c);
        fill(c+n,c+L,0);
        cl(pa); cl(pb);
    }
};
int n,m;
arr a;
arr f,g,h;
void solve(){
    scanf("%d %d",&n,&m);
    int s=n*m;
    for(int i=1;i<=s;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+s);
    fill(f,f+s*2+1,0);
    fill(g,g+s*2+1,0);
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            int c=1ll*C(n,i)*C(m,j)%mod;
            if(i+j&1) c=mod-c;
            f[(n-i)*(m-j)]=add(f[(n-i)*(m-j)],c);
        }
    }
    for(int i=0;i<=s;i++)
        f[i]=1ll*fac[i]*f[i]%mod;
    for(int i=0;i<s;i++)
        g[i]=1ll*fac[i]*(a[i+1]-a[i])%mod;
    poly::Mult(f,g,h,s*2+1);
    int ans=0;
    for(int i=0;i<s;i++)
        ans=(ans+1ll*h[i+s]*ifac[i])%mod;
    printf("%d\n",ans);
}
int main(){
    poly::r_prep();
    prep();
    int t; scanf("%d",&t);
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 21312kb

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: 9ms
memory: 20332kb

input:

1
2 2
0 0 998244352 998244352

output:

998244345

result:

ok 1 number(s): "998244345"

Test #3:

score: -100
Wrong Answer
time: 49ms
memory: 22076kb

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
118309348
270925149
575366228
709974238
761347712
304011276
14811741
366145628
638305530
240546928
484276475
603344008
926633861
161768904
239961447
329781933
315752584
578075668
259941994
600147169
402221164
890998500
154285994
181862417
47930994
273729619
36...

result:

wrong answer 31st numbers differ - expected: '641806864', found: '365932048'