QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20717#1262. Justice For Everyone_silhouette_AC ✓5218ms4040kbC++142.3kb2022-02-17 18:29:032022-05-03 11:15:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 11:15:51]
  • 评测
  • 测评结果:AC
  • 用时:5218ms
  • 内存:4040kb
  • [2022-02-17 18:29:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int Max_N=30,Mv=2e2,M=6e3;
const long long Mod=998244353;
int n,m,a[Max_N+5],b[Max_N+5],c[Max_N+5];
long long p[M+5],Inv[M+5],A[Max_N+5][Max_N+5],Ml[Mv+5],ans[M+5],f[M+5],g[M+5],res[M+5];
long long Mul(int x,int y){
	long long sum=1;
	for(;y;y>>=1,x=1ll*x*x%Mod)
	 if(y&1) sum=sum*x%Mod;
	return sum;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
	 for(int j=i+1;j<=n;j++)
	  if((a[i]<=a[j])!=(b[i]<=b[j])){
	  	puts("0"); return 0;
	  }
	for(int i=1;i<=n;i++) c[i]=b[i]-a[i],m+=c[i];
	if(m&1){ puts("0"); return 0; }
	p[0]=Inv[0]=Inv[1]=1;
	for(int i=1;i<=m;i++) p[i]=p[i-1]*i%Mod;
	for(int i=2;i<=m;i++) Inv[i]=Inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=1;i<=m;i++) Inv[i]=Inv[i]*Inv[i-1]%Mod;
	for(int e=0;e<=m;e++){
		memset(A,0,sizeof(A));
		Ml[0]=1; for(int i=1;i<=Mv;i++) Ml[i]=Ml[i-1]*e%Mod;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				int C=b[j]-a[i];
				for(int D=0;D<=C/2;D++){
					int E=C-2*D;	
					A[i][j]+=((D&1)?-1ll:1ll)*Inv[D]*Inv[E]%Mod*Ml[E]%Mod;
					A[i][j]=(A[i][j]+Mod)%Mod;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n&&A[i][i]==0;j++)
			 if(A[j][i])
			  for(int k=1;k<=n;k++)
			   A[i][k]=(A[i][k]-A[j][k]+Mod)%Mod;
			if(!A[i][i]) break;
			long long INV=Mul(A[i][i],Mod-2);
			for(int j=i+1;j<=n;j++){
				long long d=A[j][i]*INV%Mod;
				for(int k=1;k<=n;k++)
				 A[j][k]-=A[i][k]*d%Mod,
				 A[j][k]=(A[j][k]+Mod)%Mod;
			}
		}
		ans[e]=1; for(int i=1;i<=n;i++) ans[e]=ans[e]*A[i][i]%Mod;
	}
	f[0]=1;
	for(int i=0;i<=m;i++){
		for(int j=0;j<=i;j++) res[j+1]=f[j];
		for(int j=0;j<=i;j++) res[j]-=1ll*f[j]*i%Mod,res[j]=(res[j]+Mod)%Mod;
		for(int j=0;j<=i+1;j++) f[j]=res[j],res[j]=0;
	}
	for(int i=0;i<=m;i++){
		for(int j=0;j<=m;j++)
		 if(i^j) ans[i]=ans[i]*Mul((i-j+Mod)%Mod,Mod-2)%Mod;
		for(int j=0;j<=m+1;j++) res[j]=f[j];
		for(int j=m+1;j>=1;j--)
		 res[j-1]=(res[j-1]+1ll*i*res[j])%Mod;
		for(int j=0;j<=m;j++) res[j]=res[j+1];
		for(int j=0;j<=m;j++) g[j]+=ans[i]*res[j]%Mod,g[j]%=Mod; 
	}
	long long Ans=0;
	for(int i=0;i<=m;i++)
	 Ans=(Ans+g[i]*p[i]%Mod*Inv[i>>1]%Mod)%Mod;
	Ans=Ans*p[m/2]%Mod*Mul(Mul(2,Mod-2),m/2)%Mod;
	printf("%lld\n",Ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3836kb

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 3ms
memory: 3840kb

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3804kb

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3840kb

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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: 2ms
memory: 3796kb

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: 1866ms
memory: 3960kb

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

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: 111ms
memory: 3708kb

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: 160ms
memory: 3868kb

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: 5218ms
memory: 4040kb

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'