QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#849574#1262. Justice For Everyonethomas0702AC ✓1142ms4088kbC++142.2kb2025-01-09 16:20:162025-01-09 16:20:18

Judging History

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

  • [2025-01-09 16:20:18]
  • 评测
  • 测评结果:AC
  • 用时:1142ms
  • 内存:4088kb
  • [2025-01-09 16:20:16]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void rd(){}
template<typename T,typename... U> void rd(T &x,U&... arg){
	x=0;int f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
	x*=f;rd(arg...);
}
const int maxn=6005,P=998244353;
ll fpow(ll n,ll x){ll s=1;while(x){if(x&1) s=s*n%P;x>>=1,n=n*n%P;}return s;}
int N,NM,a[35],b[35],mp[205];
ll fac[maxn],inv[maxn],y[maxn],A[maxn],B[maxn];
struct Matrix{
	ll a[35][35];int n;
	Matrix(int n=0):n(n){memset(a,0,sizeof a);}
	ll *operator[](int i){return a[i];}
	ll det(){
		static ll b[35][35];
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				b[i][j]=a[i][j];
		ll ans=1;
		for(int i=1;i<=n;i++)
			for(int j=i;j<=n;j++){
				if(!b[j][i]) continue;
				swap(b[i],b[j]);
				if(i!=j) ans=P-ans;
				for(j=i+1;j<=n;j++){
					ll mul=b[j][i]*fpow(b[i][i],P-2)%P;
					for(int k=i;k<=n;k++) (b[j][k]+=(P-mul)*b[i][k]%P)%=P; 
				}
			}
		for(int i=1;i<=n;i++) ans=ans*b[i][i]%P;
		return ans;
	} 
};
int main(){
//	freopen("transform3.in","r",stdin);
//	freopen("transform.out","w",stdout);
	fac[0]=1;for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%P;
	inv[maxn-1]=fpow(fac[maxn-1],P-2);for(int i=maxn-2;~i;i--) inv[i]=inv[i+1]*(i+1)%P;
	rd(N);
	for(int i=1;i<=N;i++) rd(a[i]);
	bool flag=0;
	for(int i=1;i<=N;i++) rd(b[i]),NM+=b[i]-a[i],flag|=a[i]>b[i];
	flag|=NM&1;
	for(int i=1;i<=N;i++) mp[a[i]]=b[i];
	sort(a+1,a+N+1);
	sort(b+1,b+N+1);
	for(int i=1;i<=N;i++) flag|=mp[a[i]]!=b[i];
	if(flag) return puts("0"),0;
	for(int i=1;i<=NM/2+1;i++){
		Matrix m(N);
		for(int j=1;j<=N;j++)
			for(int k=1;k<=N;k++)
				for(int o=0,pw=1;o<=(b[k]-a[j])/2;o++,pw=(int)(1LL*pw*(P-i)%P))
					(m[j][k]+=inv[o]*inv[b[k]-a[j]-2*o]%P*pw%P)%=P;
		y[i]=m.det();
		y[i]=y[i]*inv[i-1]%P*inv[NM/2+1-i]%P;
		if((NM/2+1-i)&1) y[i]=P-y[i];
	}
	B[0]=1;
	for(int i=1;i<=NM/2+1;i++){
		for(int j=i-1;~j;j--) A[j]=(B[j]*y[i]+A[j]*(P-i)+(j?A[j-1]:0))%P;
		for(int j=i;~j;j--) B[j]=(B[j]*(P-i)+(j?B[j-1]:0))%P;
	}
	ll ans=0;
	for(int i=0;i<=NM/2;i++) (ans+=fac[NM-2*i]*inv[NM/2-i]%P*A[i]%P)%=P;
	ans=ans*fac[NM/2]%P*fpow((P+1)/2,NM/2)%P;
	printf("%lld",ans);
	return 0;
}

詳細信息

Test #1:

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

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

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

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

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

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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: 0ms
memory: 3756kb

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: 439ms
memory: 4004kb

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: 0ms
memory: 3736kb

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: 46ms
memory: 4056kb

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: 16ms
memory: 4088kb

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: 1142ms
memory: 4028kb

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'