QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723717#9572. BingoMu_SilkWA 230ms24412kbC++233.0kb2024-11-07 23:50:552024-11-07 23:50:59

Judging History

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

  • [2024-11-07 23:50:59]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:24412kb
  • [2024-11-07 23:50:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> poly;
const ll M=998244353;
ll qpow(ll a,ll b){
    a%=M;
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%M;
        a=a*a%M;
        b>>=1;
    }
    return ans;
}

const ll g=3,rg=qpow(g,M-2);
vector<int> rev;
void NTT(poly& f,int op){
    for(int i=0;i<f.size();i++)if(i<rev[i])swap(f[i],f[rev[i]]);
    for(int m=1;m<f.size();m<<=1){
        ll gn=qpow(op==1?g:rg,(M-1)/(m<<1));
        for(int j=0;j<f.size();j+=(m<<1)){
            ll w=1;
            for(int k=0;k<m;k++,w=w*gn%M){
                ll x=f[j+k],y=w*f[j+k+m]%M;
                f[j+k]=(x+y)%M;
                f[j+k+m]=(x-y+M)%M;
            }
        }
    }
    if(op==-1){
        ll inv=qpow(f.size(),M-2);
        for(int i=0;i<f.size();i++)f[i]=f[i]*inv%M;
    }
}

poly operator*(poly f,poly g){
    int len=f.size()+g.size()-1;
    int c=0;for(int t=1;t<len;t<<=1)c++;
    int deg=(1<<c);rev.resize(deg);rev[0]=0;
    for(int i=1;i<deg;i++)rev[i]=(rev[i>>1]>>1)+((i&1)<<(c-1));
    f.resize(deg);g.resize(deg);NTT(f,1);NTT(g,1);
    for(int i=0;i<deg;i++)f[i]=f[i]*g[i]%M;
    NTT(f,-1);f.resize(len);
    return f;
}

poly qpow(poly f,ll b){
    poly ans={1};
    while(b){
        if(b&1)ans=ans*f;
        f=f*f;
        b>>=1;
    }
    return ans;
}

const int N=200000;
ll fac[N],ifac[N];
void init(){
    fac[0]=1;
    for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%M;
    ifac[N-1]=qpow(fac[N-1],M-2);
    for(int i=N-2;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%M;
}

ll C(ll a,ll b){
    if(a<b||a<0)return 0;
    return fac[a]*ifac[b]%M*ifac[a-b]%M;
}

void solve(){
    int n,m;cin>>n>>m;
    vector<ll> a(n*m);
    for(int i=0;i<n*m;i++)cin>>a[i];
    sort(a.begin(),a.end());

    poly f(n*m+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int sgn=(n+m-i-j)%2==0?1:M-1;
            f[i*j]=(f[i*j]+fac[i*j]*C(n,i)%M*C(m,j)%M*sgn)%M;
        }
    }

    // for(int i=0;i<f.size();i++)cout<<f[i]<<" ";
    // cout<<"\n";

    poly g(n*m+1);
    for(int i=0;i<=n*m;i++)g[i]=ifac[n*m-i];
    f=f*g;
    f=poly(f.begin()+n*m,f.end());
    for(int i=0;i<f.size();i++)f[i]=f[i]*ifac[i]%M;
    f[0]=0;

    // for(int i=0;i<f.size();i++)cout<<f[i]<<" ";
    // cout<<"\n";

    int l=0,r;
    vector<pair<ll,ll>> v;
    while(l<n*m){
        r=l;
        while(r<n*m&&a[r]==a[l])r++;r--;
        
        v.push_back({a[l],f[n*m-l]*fac[n*m-l]%M*fac[l]%M});
        l=r+1;
    }
    // for(int i=0;i<v.size();i++)cout<<v[i].first<<":"<<v[i].second<<"\n";
    for(int i=0;i+1<v.size();i++)v[i].second=(v[i].second-v[i+1].second+M)%M;
    ll ans=0;
    for(int i=0;i<v.size();i++){
        ans=(ans+v[i].first*v[i].second)%M;
        // cout<<v[i].first<<":"<<v[i].second<<"\n";
    }
    cout<<ans<<"\n";
    
}

int main(){
    init();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n=1;
    cin>>n;
    while(n--)solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 6940kb

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: 3ms
memory: 6960kb

input:

1
2 2
0 0 998244352 998244352

output:

998244345

result:

ok 1 number(s): "998244345"

Test #3:

score: 0
Accepted
time: 79ms
memory: 6852kb

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
64...

result:

ok 900 numbers

Test #4:

score: 0
Accepted
time: 116ms
memory: 6756kb

input:

400
1 995
548100968 635656907 177366910 971271357 314579375 529572241 948721678 455918644 95745688 164857981 499083775 827896554 496889261 111294651 646048809 758286431 163045934 917399362 189372614 267754648 966443706 921589740 228089960 473153545 482816423 37567957 495730380 864445591 568695110 78...

output:

954668084
677509135
636173666
415373646
477286237
209886549
398423120
24466622
672440292
390142124
498517438
305197486
239833057
500821845
475519894
347179487
974036742
810602822
75196204
48378743
393961176
290898056
957916898
434124418
663457674
225283495
704304053
338701802
670053839
137083082
165...

result:

ok 400 numbers

Test #5:

score: 0
Accepted
time: 184ms
memory: 7564kb

input:

40
92 99
14480275 12892621 932457558 584861415 926346518 101583802 498448003 884757899 463949215 661256632 872663851 651132350 565253214 18404795 810166895 145370572 123351313 298382303 777283720 775900024 613503856 817112784 713304484 541301622 595768594 550989875 960159831 571815058 777864097 3608...

output:

614712898
16225927
313765200
824491114
60971514
769510634
58341639
808667102
527187053
319496150
267177120
409701892
245708713
115397703
928197397
533118123
931076329
448328887
672878477
180728812
385639338
504093069
846218180
981546177
906805965
315620628
863877552
348963788
781585156
982673320
275...

result:

ok 40 numbers

Test #6:

score: 0
Accepted
time: 156ms
memory: 7512kb

input:

40
86 92
479103936 690362573 387313968 428679987 770097821 67859949 744428797 919332570 530162857 389639443 851979342 310332074 863845681 155743453 442066584 996725021 385646576 447381083 64960590 818019444 260564007 16381359 36238584 609449698 12466296 532193395 262308857 279184524 454814687 400578...

output:

147127348
995441625
947321329
200561175
846810174
626764591
235790337
30932003
384829067
254218916
20342301
451884441
634808121
241161955
246093492
515701050
978130791
502129313
3431507
775910032
464454612
153447682
53092548
316439192
101505498
40191013
225025922
133184210
209384134
330521977
360716...

result:

ok 40 numbers

Test #7:

score: 0
Accepted
time: 230ms
memory: 24280kb

input:

2
447 447
790583748 764745604 779691526 67598288 308196334 738524513 685610494 336125979 294155123 651917356 898366384 420012139 529304950 133567869 630219750 62853597 606184670 383809162 43962071 826608376 652871696 860138865 675639996 444122802 823442992 841633845 125418467 211407031 726738308 984...

output:

506347658
891054810

result:

ok 2 number(s): "506347658 891054810"

Test #8:

score: -100
Wrong Answer
time: 229ms
memory: 24412kb

input:

2
100 2000
414412015 610256524 548060717 581032168 761297097 50124687 831351681 906381893 842125801 82512258 734351512 844649420 370666628 791011946 232557748 968208094 238084359 933173727 306257334 509581201 774756848 370039888 322700146 641635730 8423279 909781921 238370638 28574480 725141803 9941...

output:

317953977
935545330

result:

wrong answer 1st numbers differ - expected: '380238486', found: '317953977'