QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389492#1262. Justice For EveryoneRedreamMerAC ✓504ms12412kbC++233.6kb2024-04-14 14:34:462024-04-14 14:34:47

Judging History

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

  • [2024-04-14 14:34:47]
  • 评测
  • 测评结果:AC
  • 用时:504ms
  • 内存:12412kb
  • [2024-04-14 14:34:46]
  • 提交

answer

// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define PB emplace_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) { rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1]; }

namespace poly {
	const int M = 1 << 21, mod = 998244353;
	int qp(int n, int m = mod - 2) {
		int res = 1;
		for (; m; m >>= 1) {
			if (m & 1) res = res * n % mod;
			n = n * n % mod;
		}
		return res;
	}
	int len, r[M + 5], w[2][M + 5], L;
 	int sqrt(int n) {return 1;}
 	const int i2 = qp(2);
	int add(int n, int m) {return n + m >= mod ? n + m - mod : n + m;}
	void init(int n) {
		len = 1;
		for(; len < n; len <<= 1);
		w[0][0] = w[1][0] = 1;
		w[0][1] = qp(3, (mod - 1) / len), w[1][1] = qp(w[0][1]);
		rep(i, 1, len - 1) {
			r[i] = (r[i >> 1] >> 1) | (i & 1 ? (len >> 1) : 0);
			w[0][i] = w[0][i - 1] * w[0][1] % mod;
			w[1][i] = w[1][i - 1] * w[1][1] % mod;
		}
	}
	void NTT(vi &f, int o) {
		f.resize(len);
		rep(i, 0, len - 1) if(i > r[i]) swap(f[i], f[r[i]]);
		for(int i = 1, q = len >> 1; i < len; i <<= 1, q >>= 1) {
			for(int j = 0; j < len; j += i << 1) {
				rep(k, 0, i - 1) {
					int tmp = f[j + k + i] * w[o][k * q] % mod;
					f[j + k + i] = add(f[j + k], mod - tmp);
					f[j + k] = add(f[j + k], tmp);
				}
			}
		}
		if(o) {
			const int iv = qp(len);
			rep(i, 0, len - 1) (f[i] *= iv) %= mod;
		}
	}
}
using namespace poly;

const int N = 200;
int a, b, s[N + 5], t[N + 5], g[N + 5][N + 5];

int fac[N * 30 + 5], inv[N * 30 + 5];
void initc() {
	fac[0] = fac[1] = 1;
	rep(i, 2, N * 30) fac[i] = fac[i - 1] * i % mod;
	inv[N * 30] = qp(fac[N * 30]);
	per(i, N * 30 - 1, 0) inv[i] = inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {return fac[n] * inv[m] % mod * inv[n - m] % mod;}

int det() {
	int res = 1;
	rep(i, 1, a) {
		rep(j, i, a) if(g[j][i]) {
			swap(g[j], g[i]);
			if(j > i) res = -res;
			break;
		}
		rep(j, 1, a) if(i != j) {
			int tmp = mod - g[j][i] * qp(g[i][i]) % mod;
			rep(k, i, a) (g[j][k] += tmp * g[i][k]) %= mod;
		}
	}
	// rep(i, 1, a) rep(j, 1, a) cout << g[i][j] << " \n"[j == a];
	rep(i, 1, a) (res *= g[i][i]) %= mod;
	return (res + mod) % mod;
}

signed main() {
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	initc();
	cin >> a;
	rep(i, 1, a) cin >> s[i];
	rep(i, 1, a) cin >> t[i], b += t[i] - s[i];
	rep(i, 1, a) rep(j, i + 1, a) if((s[i] < s[j]) != (t[i] < t[j])) return cout << 0, 0;

	if(b & 1) return cout << 0, 0;

	init(max(N, b / 2) + 1);
	vi f[N];
	rep(i, 0, N - 1) {
		f[i].resize(len);
		rep(j, 0, i / 2) f[i][j] = inv[j] * inv[i - j * 2] % mod;
		NTT(f[i], 0);
		// cout << f[i][0] << endl;
	}

	vi res(len);
	rep(i, 0, len - 1) {
		rep(j, 1, a) rep(k, 1, a) {
			if(s[j] <= t[k]) g[j][k] = f[t[k] - s[j]][i];
			else g[j][k] = 0;
		}
		res[i] = det();
	}
	NTT(res, 1);

	// rep(i, 0, len - 1) cout << res[i] << " \n"[i == len - 1];
	// return 0;

	auto sg = [&] (int n) {return n & 1 ? mod - 1 : 1;};
	int ans = 0;
	rep(i, 0, b / 2) {
		(ans += sg(i) * res[i] % mod * fac[b / 2] % mod * fac[b - 2 * i] % mod * inv[b / 2 - i]) %= mod;
	}
	// cout << ans << endl;
	// return 0;
	cout << ans * qp((mod + 1) / 2, b / 2) % mod;
	return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 6244kb

input:

3
1 2 3
3 4 5

output:

1

result:

ok answer is '1'

Test #2:

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

input:

3
1 2 3
7 8 9

output:

42

result:

ok answer is '42'

Test #3:

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

input:

3
1 4 7
3 6 9

output:

6

result:

ok answer is '6'

Test #4:

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

input:

1
1
3

output:

0

result:

ok answer is '0'

Test #5:

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

input:

1
1
1

output:

1

result:

ok answer is '1'

Test #6:

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

input:

2
1 4
4 7

output:

1

result:

ok answer is '1'

Test #7:

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

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

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: 252ms
memory: 9324kb

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

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: 65ms
memory: 6896kb

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: 9ms
memory: 6688kb

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: 504ms
memory: 12412kb

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'