QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209684#6325. Peaceful Resultsc20230507WA 265ms78228kbC++143.3kb2023-10-10 16:33:282023-10-10 16:33:28

Judging History

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

  • [2023-10-10 16:33:28]
  • 评测
  • 测评结果:WA
  • 用时:265ms
  • 内存:78228kb
  • [2023-10-10 16:33:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e6+10;
const int INF=0x3f3f3f3f;
const int mod=998244353;
const int G=3;
int n,sta[3][3],f[maxn],inv[maxn];
int a[6][7],y[maxn],rev[maxn],limit;
int l1[maxn],l2[maxn],l3[maxn];
int qpow(int x,int y){
    int val=1;
    while(y){
        if(y&1)val=val*x%mod;
        x=x*x%mod,y/=2;
    }
    return val;
}
int lcm(int x,int y){
    return x/__gcd(x,y)*y;
}
void init(){//高斯消元
    for(int i=0;i<6;i++){
        int id=0;
        for(int j=i;j<6;j++)if(a[j][i])id=j;        
        swap(a[i],a[id]);
        for(int j=0;j<6;j++){
            if(j==i)continue;
            if(a[j][i]){
                int v=lcm(a[j][i],a[i][i]);
                int val1=v/a[i][i],val2=v/a[j][i];
                for(int k=0;k<7;k++)a[j][k]=a[j][k]*val2,a[i][k]=a[i][k]*val1;
                for(int k=0;k<7;k++)a[j][k]=a[j][k]-a[i][k];
            }
        }
    }
    for(int i=0;i<6;i++){
        if(a[i][6]%a[i][i]){
            cout<<0;
            exit(0);
        }
        y[i]=a[i][6]/a[i][i];
    }
}
void NTT(int dp[],int flag){
    for(int i=0;i<limit;i++)if(i<rev[i])swap(dp[i],dp[rev[i]]);
    for(int mid=1;mid<limit;mid*=2){
        int w=qpow(G,(mod-1)/2/mid);
        if(flag==-1)w=qpow(w,mod-2);
        for(int i=0;i<limit;i=i+2*mid){
            for(int j=i,wn=1;j<i+mid;j++,wn=wn*w%mod){
                int x=dp[j],y=dp[j+mid]*wn%mod;
                dp[j]=(x+y)%mod,dp[j+mid]=(x-y+mod)%mod;
            }
        }
    }
    if(flag==-1){
        int invs=qpow(limit,mod-2);
        for(int i=0;i<limit;i++)dp[i]=dp[i]*invs%mod;
    }
}
void solve(){
    limit=1;
    int v=0,N=n;
    n=sta[0][0];
    while(limit<=2*n)limit*=2,v++;
    for(int i=1;i<limit;i++)rev[i]=((rev[i>>1]>>1)|((i&1)<<(v-1)));
    int v1=max(-y[0],-y[1]),v2=max(-y[2],-y[3]),v3=max(-y[4],-y[5]);
    v1=max(v1,(int)0),v2=max(v2,(int)0),v3=max(v3,(int)0);
    for(int i=v1;i<=n;i++)l1[i]=inv[i]*inv[i+y[0]]%mod*inv[i+y[1]]%mod;
    for(int i=v2;i<=n;i++)l2[i]=inv[i]*inv[i+y[2]]%mod*inv[i+y[3]]%mod;
    for(int i=v3;i<=n;i++)l3[i]=inv[i]*inv[i+y[4]]%mod*inv[i+y[5]]%mod;
    NTT(l1,1);NTT(l2,1);NTT(l3,1);
    for(int i=0;i<limit;i++)l1[i]=l1[i]*l2[i]%mod*l3[i]%mod;
    NTT(l1,-1);
    cout<<l1[n]*f[N]%mod;
}
signed main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n;
    f[0]=1;
    for(int i=1;i<=n;i++)f[i]=f[i-1]*i%mod;
    inv[n]=qpow(f[n],mod-2);
    for(int i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)cin>>sta[i][j];
    }
    //start
    a[0][0]=a[0][2]=a[0][4]=1;
    a[0][6]=sta[0][1]-sta[0][0];
    
    a[1][1]=a[1][3]=a[1][5]=1;
    a[1][6]=sta[0][2]-sta[0][0];

    a[2][0]=a[2][5]=1,a[2][3]=a[2][4]=-1;
    a[2][6]=sta[1][1]-sta[1][0];

    a[3][1]=a[3][2]=1,a[3][3]=a[3][4]=-1;
    a[3][6]=sta[1][2]-sta[1][0];

    a[4][0]=a[4][3]=1,a[4][2]=a[4][5]=-1;
    a[4][6]=sta[2][1]-sta[2][0];

    a[5][1]=a[5][4]=1,a[5][2]=a[5][5]=-1;
    a[5][6]=sta[2][2]-sta[2][0];
    // for(int i=0;i<6;i++){
    //     for(int j=0;j<6;j++){
    //         cout<<a[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    init();
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 0 0
1 1 0
1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 7852kb

input:

3
0 1 2
3 0 0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 62ms
memory: 25792kb

input:

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111

output:

383902959

result:

ok 1 number(s): "383902959"

Test #4:

score: 0
Accepted
time: 248ms
memory: 71068kb

input:

1500000
500000 500000 500000
500000 500000 500000
500000 500000 500000

output:

355543262

result:

ok 1 number(s): "355543262"

Test #5:

score: 0
Accepted
time: 258ms
memory: 68692kb

input:

1499999
499999 499999 500001
499999 499999 500001
499999 499999 500001

output:

934301164

result:

ok 1 number(s): "934301164"

Test #6:

score: 0
Accepted
time: 14ms
memory: 40612kb

input:

1500000
1 0 1499999
1499999 1 0
0 1499999 1

output:

1500000

result:

ok 1 number(s): "1500000"

Test #7:

score: 0
Accepted
time: 8ms
memory: 38500kb

input:

1499999
0 749999 750000
750000 0 749999
749999 750000 0

output:

713966599

result:

ok 1 number(s): "713966599"

Test #8:

score: 0
Accepted
time: 0ms
memory: 15896kb

input:

1
1 0 0
0 0 1
0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 2ms
memory: 15988kb

input:

1
0 1 0
0 1 0
0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: 0
Accepted
time: 0ms
memory: 7772kb

input:

1
0 0 1
1 0 0
1 0 0

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 237ms
memory: 71768kb

input:

1499999
500000 500000 499999
499999 499999 500001
499999 499999 500001

output:

617065435

result:

ok 1 number(s): "617065435"

Test #12:

score: 0
Accepted
time: 0ms
memory: 15980kb

input:

2
1 1 0
0 0 2
0 0 2

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 265ms
memory: 69232kb

input:

1500000
500000 500001 499999
499999 500000 500001
499999 500000 500001

output:

925862004

result:

ok 1 number(s): "925862004"

Test #14:

score: 0
Accepted
time: 113ms
memory: 39340kb

input:

629197
210878 201408 216911
145293 266423 217481
194751 220179 214267

output:

447295633

result:

ok 1 number(s): "447295633"

Test #15:

score: 0
Accepted
time: 113ms
memory: 41020kb

input:

579097
200209 204257 174631
149110 148890 281097
138034 263752 177311

output:

71830925

result:

ok 1 number(s): "71830925"

Test #16:

score: 0
Accepted
time: 57ms
memory: 29060kb

input:

354224
100316 63899 190009
69306 123829 161089
140523 76088 137613

output:

44852283

result:

ok 1 number(s): "44852283"

Test #17:

score: 0
Accepted
time: 245ms
memory: 63172kb

input:

1229851
383009 323934 522908
551226 311238 367387
547622 353128 329101

output:

39721313

result:

ok 1 number(s): "39721313"

Test #18:

score: 0
Accepted
time: 125ms
memory: 42100kb

input:

858452
195309 312080 351063
384805 51797 421850
200466 301164 356822

output:

506491992

result:

ok 1 number(s): "506491992"

Test #19:

score: -100
Wrong Answer
time: 23ms
memory: 78228kb

input:

1424218
661653 323895 438670
467846 488045 468327
369769 343207 711242

output:

0

result:

wrong answer 1st numbers differ - expected: '782021141', found: '0'