QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390713#1262. Justice For EveryonezhaohaikunAC ✓267ms3948kbC++203.6kb2024-04-15 20:21:112024-04-15 20:21:12

Judging History

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

  • [2024-04-15 20:21:12]
  • 评测
  • 测评结果:AC
  • 用时:267ms
  • 内存:3948kb
  • [2024-04-15 20:21:11]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[33m[" << __LINE__ << "]\033[0m "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 35, M = 210, MOD = 998244353, inv2 = (MOD + 1) >> 1;
inline void add(int &x, ll y) {x = (x + y) % MOD;}
int n, a[N], b[N], s, val[M], pw[M], f[N][N], ans, pw2[N * M], ipw2[N * M];
int fac[N * M], ifac[N * M], inv[N * M];
inline int power(int x, int y = MOD - 2) {
	int ans = 1;
	for (; y; x = (ll) x * x % MOD, y >>= 1)
		if (y & 1) ans = (ll) ans * x % MOD;
	return ans;
}
inline void binom(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
	F(i, 1, x) fac[i] = (ll) fac[i - 1] * i % MOD, ifac[i] = (ll) ifac[i - 1] * inv[i] % MOD;
}
inline int C(int x, int y) {return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;}
struct Lag {
	int n, y[M * N], a[M * N], ans[M * N];
	void mul(int b) { // * (x + b)
		DF(i, n, 0) a[i] = ((i ? a[i - 1] : 0) + (ll) a[i] * b) % MOD;
	}
	void div(int b) { // / (x + b)
		b = power(b);
		F(i, 0, n) a[i] = (ll) (a[i] - (i ? a[i - 1] : 0) + MOD) * b % MOD;
	}
	void solve() {
		ms(a, 0), ms(ans, 0);
		a[0] = 1;
		F(i, 1, n + 1) mul(MOD - i);
		F(i, 1, n + 1) {
			div(MOD - i);
			int coef = 1;
			F(j, 1, n + 1)
				if (i != j) coef = (ll) coef * (i - j + MOD) % MOD;
			coef = (ll) y[i] * power(coef) % MOD;
			F(j, 0, n) add(ans[j], (ll) a[j] * coef);
			mul(MOD - i);
		}
	}
} F;
int det() {
	int ans = 1;
	F(i, 1, n) {
		F(j, i + 1, n)
			if (f[j][i]) {
				ans = MOD - ans;
				swap(f[i], f[j]);
				break;
			}
		if (!f[i][i]) return 0;
		ans = (ll) ans * f[i][i] % MOD;
		int inv = power(f[i][i]);
		F(j, 1, n) if (i != j) {
			int t = (ll) f[j][i] * inv % MOD;
			F(k, i, n) add(f[j][k], MOD - (ll) t * f[i][k] % MOD);
		}
	}
	return ans;
}
void init(int n) {
	pw2[0] = ipw2[0] = 1;
	F(i, 1, n) pw2[i] = 2 * pw2[i - 1] % MOD, ipw2[i] = (ll) inv2 * ipw2[i - 1] % MOD;
}
signed main() {
	binom(200 * 30);
	init(200 * 30);
	read(n);
	F(i, 1, n) read(a[i]);
	F(i, 1, n) {
		read(b[i]), s += b[i] - a[i];
		if (b[i] < a[i]) {
			puts("0");
			return 0;
		}
	}
	if (s & 1) {
		puts("0");
		return 0;
	}
	F(i, 1, n)
		F(j, 1, n)
			if ((a[i] < a[j]) != (b[i] < b[j])) {
				puts("0");
				return 0;
			}
	s /= 2;
	F.n = s;
	F(i, 1, s + 1) {
		pw[0] = 1;
		F(j, 1, 200) pw[j] = (ll) i * pw[j - 1] % MOD;
		F(j, 0, 200) {
			val[j] = 0;
			F(k, 0, j / 2) add(val[j], (ll) pw[k] * ifac[k] % MOD * ifac[j - 2 * k]);
		}
		F(p, 1, n)
			F(q, 1, n)
				if (a[p] <= b[q])
					f[p][q] = val[b[q] - a[p]];
		F.y[i] = det();
		// if (i == 0) debug << (ll) F.y[i] * fac[2 * s] % MOD << endl;
	}
	F.solve();
	F(i, 0, s) {
		int t = (ll) F.ans[i] * fac[s] % MOD * fac[2 * (s - i)] % MOD * ifac[s - i] % MOD;// * ipw2[s - i] % MOD;
		// debug << i << " " << t << " " << s << endl;
		if (i & 1) add(ans, MOD - t);
		else add(ans, t);
	}
	cout << (ll) ans * ipw2[s] % MOD;
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

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

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

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

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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: 1ms
memory: 3680kb

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: 135ms
memory: 3924kb

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: 1ms
memory: 3732kb

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: 23ms
memory: 3864kb

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: 23ms
memory: 3800kb

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: 267ms
memory: 3892kb

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'