QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389254#1262. Justice For EveryoneOccDreamerAC ✓3384ms14492kbC++143.7kb2024-04-14 08:18:262024-04-14 08:18:26

Judging History

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

  • [2024-04-14 08:18:26]
  • 评测
  • 测评结果:AC
  • 用时:3384ms
  • 内存:14492kb
  • [2024-04-14 08:18:26]
  • 提交

answer

//code by Emissary
#include<bits/stdc++.h>

#define vc vector
#define db double
#define fi first
#define se second
#define ll long long
#define mk make_pair
#define pb push_back
#define RI register int
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define OccDreamer
//#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(int x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(int x){write(x), putchar(32);}
	inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;

const int MAXN = 505;
const int mod = 998244353;

int fac[MAXN*30], ifac[MAXN*30], inv[MAXN*30], T;
int n, m, a[MAXN*30], b[MAXN*30], x[MAXN*30], y[MAXN*30], c[MAXN*30];

int G[MAXN*30], F[MAXN*30], xx[MAXN*30], now;

struct matrix{
	ll a[MAXN][MAXN];	
	inline int det(int n){
		ll ans=1, times=1;
		for(int i=1;i<=n;++i){
			for(int j=i+1;j<=n;++j){
				while(a[i][i]){
					int d=a[j][i]/a[i][i];
					if(d){
						for(int p=i;p<=n;++p) a[j][p]-=d*a[i][p], a[j][p]=(a[j][p]%mod+mod)%mod;
					}
					swap(a[i],a[j]), times*=-1;
				}
				swap(a[i],a[j]), times*=-1;
			}
			ans=ans*a[i][i]%mod;
		}
		if(times==-1) ans=mod-ans;
		return ans%mod;	
	}
}A, B;

struct poly{
	vc<int> p;
	bool vis[202*33];
	int res[202*33];
	inline int val(int x){
		if(vis[x]) return res[x]; vis[x]=1;
		int s=0, t=p.size(), ans=0;
		for(int i=t-1;i>=0;--i) ans=1ll*ans*x%mod+p[i], ans%=mod;
		return res[x]=ans;
	}
}D[202];

inline ll Quickpow(ll x, ll y){
	ll z=1;
	while(y){
		if(y&1) z=z*x%mod;
		x=x*x%mod; y>>=1;
	}
	return z;
}

inline void prework(int lim){
	fac[0]=ifac[0]=1;
	for(int i=1;i<=lim;++i) fac[i]=1ll*fac[i-1]*i%mod, ifac[i]=Quickpow(fac[i],mod-2);
	return ;
}	

signed main(){
	n=read(); prework(402*30);
	for(int i=1;i<=n;++i) a[i]=read(), T-=a[i];
	for(int i=1;i<=n;++i) b[i]=read(), T+=b[i];
	if(T&1) return eprint(0), 0; T>>=1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j) if((a[i]<a[j])!=(b[i]<b[j])) return eprint(0), 0;
	for(int i=0;i<=200;++i){
		int o=i>>1;
		D[i].p.resize(o+1);
		for(int j=0;j<=o;++j) D[i].p[j]=1ll*ifac[j]*ifac[i-2*j]%mod;	
	}
	D[201].p.pb(0);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(b[j]<a[i]) B.a[i][j]=201;
			else B.a[i][j]=b[j]-a[i];
	for(int i=1;i<=202*n;++i){
		for(int j=1;j<=n;++j)
			for(int k=1;k<=n;++k) A.a[j][k]=D[B.a[j][k]].val(i);
		//cerr << "ok" << i << endl;
		x[i]=i, y[i]=A.det(n);
	}
	now=0; G[0]=1; int ans=0;
	for(int i=1;i<=202*n;++i){
		for(int j=now+1;j>=1;--j) G[j]=(1ll*G[j-1]-1ll*x[i]*G[j]%mod+mod)%mod;	
		G[0]=1ll*G[0]*(mod-x[i])%mod; ++now;
	}
	inv[0]=1;
	for(int i=1;i<=202*n;++i) inv[i]=Quickpow(i,mod-2);
	for(int i=1;i<=202*n;++i){
		//cerr << "ok:" << i << endl;
		int w=1;
		for(int j=1;j<=202*n;++j){
			if(i==j) continue;
			w=1ll*w*(x[i]-x[j]+mod)%mod;
		}
		w=1ll*Quickpow(w,mod-2)*y[i]%mod;
		for(int j=0;j<=now;++j) F[j]=G[j];
		F[0]=1ll*F[0]*Quickpow(mod-x[i],mod-2)%mod;
		for(int j=1;j<=now;++j) F[j]=1ll*(F[j-1]-F[j]+mod)%mod*inv[x[i]]%mod;
		
		for(int j=0;j<now;++j) xx[j]+=1ll*w*F[j]%mod, xx[j]%=mod;
	}
	for(int i=0;i<=202*n;++i)
		if(i<=T) ans+=1ll*xx[i]*fac[2*(T-i)]%mod*fac[T]%mod*ifac[T-i]%mod*Quickpow(mod-1,i)%mod, ans%=mod;	
	eprint(1ll*ans*Quickpow((mod+1)>>1,T)%mod);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 12260kb

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 16ms
memory: 14164kb

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

score: 0
Accepted
time: 10ms
memory: 14188kb

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

score: 0
Accepted
time: 6ms
memory: 14124kb

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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: 12044kb

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: 3300ms
memory: 12416kb

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: 10052kb

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: 2794ms
memory: 14492kb

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: 221ms
memory: 14204kb

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: 3384ms
memory: 12268kb

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'