QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20899#1262. Justice For EveryonehouzhiyuanakioiAC ✓944ms3896kbC++2.3kb2022-02-21 00:48:252022-05-03 11:51:53

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:51:53]
  • 评测
  • 测评结果:AC
  • 用时:944ms
  • 内存:3896kb
  • [2022-02-21 00:48:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int p=998244353;
int bb[210]={};
int qow(int a,int n){
	int ans=1;
	for(;n;n>>=1){
		if(n&1) ans=((long long)ans*a)%p;
		a=((long long)a*a)%p; 
	}
	return ans;
}
inline int inverse(int a){
	return qow(a,p-2);
}
int aa[50][50];
int det(int m){
	int ans=1;
	for(int i=1;i<=m;i++){
		for(int j=i+1;j<=m;j++){
			if(aa[j][i]){
				for(int k=1;k<=m;k++) swap(aa[i][k],aa[j][k]);
                ans=p-ans;
				break;
			}
		}
		int u=inverse(aa[i][i]);
		for(int j=i+1;j<=m;j++){
			int uu=((long long)u*aa[j][i])%p;
			for(int k=1;k<=m;k++) aa[j][k]=(aa[j][k]+(long long)(p-uu)*aa[i][k])%p; 
		}
	}
	for(int i=1;i<=m;i++) ans=((long long)ans*aa[i][i])%p;
    return ans;
}
int fac[10000];
int infac[10000];
int anss[10000]={};
int t[10000];
int u[10000]={}; 
int main(){
	fac[0]=1;
	for(int i=1;i<10000;i++) fac[i]=((long long)fac[i-1]*i)%p;
	for(int i=0;i<10000;i++) infac[i]=inverse(fac[i]);
	int n,a[50],b[50];
	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++) bb[a[i]]=b[i];
	for(int i=1,tot=0;i<=200;i++){
		if(bb[i]){
			a[++tot]=i;
			b[tot]=bb[i];
		}
	}
	for(int i=2;i<=n;i++) if(b[i]<=b[i-1]) {
		printf("0");
		return 0;
	}
	int s=0;
	for(int i=1;i<=n;i++) s+=b[i]-a[i];
	if((s<0)||(s&1)){
		printf("0");
		return 0;
	} 
	s/=2;
	u[0]=1;
	for(int i=0;i<=s;i++){
		u[i+1]=1;
		for(int j=i;j>=1;j--) u[j]=(u[j-1]+(long long)(p-i)*u[j])%p;
		u[0]=((long long)(p-i)*u[0])%p;
	}
	for(int i=0;i<=s;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				aa[j][k]=0;
				if(b[k]>=a[j]) for(int o=(b[k]-a[j])/2;o>=0;o--) aa[j][k]=((long long)i*aa[j][k]+(long long)infac[o]*infac[b[k]-a[j]-2*o])%p;
                //if(i==0) cout<<aa[j][k]<<endl;
			}
		}
		int w=det(n);
        //if(i==1) cout<<(w*144ll)%p<<endl;
		w=((((long long)infac[i]*infac[s-i])%p)*w)%p;
		if((s-i)&1) w=(p-w)%p;
		t[s]=1;
		for(int j=s-1;j>=0;j--) t[j]=(u[j+1]+(long long)i*t[j+1])%p;
		for(int j=0;j<=s;j++) anss[j]=(anss[j]+(long long)t[j]*w)%p;
	}
	int ans=0;
	for(int j=0,jj=1;j<=s;j++,jj=p-jj) ans=(ans+(((((long long)infac[s-j]*fac[2*s-2*j])%p)*jj)%p)*anss[j])%p;
	ans=((long long)ans*qow(2,p-1-s))%p;
    printf("%lld",((long long)ans*fac[s])%p);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

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

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

score: 0
Accepted
time: 4ms
memory: 3884kb

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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: 4ms
memory: 3672kb

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: 331ms
memory: 3840kb

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: 4ms
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: 36ms
memory: 3828kb

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: 17ms
memory: 3888kb

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: 944ms
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
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'