QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389246#1262. Justice For EveryoneNATURAL6AC ✓2282ms4012kbC++142.5kb2024-04-14 08:04:272024-04-14 08:04:27

Judging History

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

  • [2024-04-14 08:04:27]
  • 评测
  • 测评结果:AC
  • 用时:2282ms
  • 内存:4012kb
  • [2024-04-14 08:04:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
inline void fmod(int &x)
{
    if(x>=mod)x-=mod;
    return ;
}
inline int qread()
{
    int a=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
    return a*f;
}
inline int qpow(long long x,int y)
{
    long long cx=1;
    while(y)
    {
        (y&1)&&((cx*=x)%=mod);
        (x*=x)%=mod;
        y>>=1;
    }
    return cx;
}
int n,t,ans,a[40],b[40],jc[10010],fac[10010],Y[10010],sum,LGV[40][40],A[10010],B[10010];
map<int,int>mp[210];
inline int det()
{
    int an=1;
    for(int i=1,inv;i<=n;++i)
    {
    	if(!LGV[i][i])
    	{
    		for(int j=i+1;j<=n;++j)if(LGV[j][i]){swap(LGV[j],LGV[i]);break;}
    		an=mod-an;
		}
        inv=qpow(LGV[i][i],mod-2);
        for(int j=i+1,x;j<=n;++j)
        {
            x=1ll*inv*LGV[j][i]%mod;x=mod-x;
            for(int k=i;k<=n;++k)LGV[j][k]=(1ll*LGV[j][k]+1ll*x*LGV[i][k])%mod;
        }
    }
    for(int i=1;i<=n;++i)an=1ll*an*LGV[i][i]%mod;
    return an;
}
inline int solve(int x)
{
    for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
    {
        LGV[i][j]=0;
        for(int k=0,X=1;k<=(b[j]-a[i])>>1;++k,X=1ll*X*x%mod)
        {
            LGV[i][j]=(1ll*LGV[i][j]+1ll*fac[k]*fac[b[j]-a[i]-(k<<1)]%mod*X)%mod;
        }
    }
    return det();
}
inline int get_inv(int x){return 1ll*fac[x]*jc[x-1]%mod;}
int main()
{
    n=qread();jc[0]=fac[0]=sum=1;
    for(int i=1;i<=n;++i)a[i]=qread();
    for(int i=1;i<=n;++i)sum+=(b[i]=qread()),mp[a[i]][b[i]]=1;
    sort(a+1,a+1+n);sort(b+1,b+1+n);
    for(int i=1;i<=sum;++i)jc[i]=1ll*jc[i-1]*i%mod;
    fac[sum]=qpow(jc[sum],mod-2);
    for(int i=sum;i;--i)fac[i-1]=1ll*fac[i]*i%mod;
    for(int i=1;i<=sum;++i)
	{
		Y[i]=solve(i);
		for(int j=1;j<i;++j)Y[i]=1ll*Y[i]*get_inv(i-j)%mod;
		for(int j=i+1;j<=sum;++j)Y[i]=1ll*Y[i]*(mod-get_inv(j-i))%mod;
	}
	B[0]=1;
    for(int i=1;i<=sum;++i)
    {
    	for(int j=i-1;~j;--j)A[j]=(1ll*A[j]*(mod-i)+1ll*Y[i]*B[j]+(j?A[j-1]:0))%mod;
    	for(int j=i;~j;--j)B[j]=(1ll*B[j]*(mod-i)+(j?B[j-1]:0))%mod;
	}
    for(int i=1;i<=n;++i)
    {
        t+=(b[i]-a[i]);
        if(!mp[a[i]][b[i]])return puts("0"),0;
    }
    if(t&1)return puts("0"),0;
    t>>=1;
    for(int i=0;i<=t;++i)ans=(1ll*ans+1ll*(i&1?mod-1:1)*jc[(t-i)<<1]%mod*fac[t-i]%mod*A[i])%mod;
    ans=1ll*ans*jc[t]%mod*qpow(qpow(2,mod-2),t)%mod;
	printf("%d\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3852kb

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

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

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

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

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

score: 0
Accepted
time: 24ms
memory: 3712kb

input:

10
10 9 8 7 6 1 2 3 4 5
11 12 13 114 115 120 129 128 127 126

output:

0

result:

ok answer is '0'

Test #8:

score: 0
Accepted
time: 855ms
memory: 3688kb

input:

30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 131

output:

0

result:

ok answer is '0'

Test #9:

score: 0
Accepted
time: 855ms
memory: 3896kb

input:

30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

output:

936606510

result:

ok answer is '936606510'

Test #10:

score: 0
Accepted
time: 548ms
memory: 3788kb

input:

30
16 21 33 44 51 60 71 81 91 100 110 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199
110 111 112 113 114 115 116 117 118 119 120 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199

output:

0

result:

ok answer is '0'

Test #11:

score: 0
Accepted
time: 540ms
memory: 4012kb

input:

30
16 21 33 44 51 60 71 81 91 100 110 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 199
110 111 112 113 114 115 116 117 118 119 120 122 131 144 155 160 162 171 172 174 177 179 187 188 189 191 192 193 194 200

output:

836228983

result:

ok answer is '836228983'

Test #12:

score: 0
Accepted
time: 33ms
memory: 3928kb

input:

10
10 9 8 7 6 5 4 3 2 1
110 109 108 107 106 105 104 103 102 101

output:

422463757

result:

ok answer is '422463757'

Test #13:

score: 0
Accepted
time: 2282ms
memory: 4000kb

input:

30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

output:

575061951

result:

ok answer is '575061951'