結果
問題 | No.1857 Gacha Addiction |
ユーザー | Mitarushi |
提出日時 | 2021-12-31 22:51:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,371 ms / 6,000 ms |
コード長 | 2,354 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 292,392 KB |
最終ジャッジ日時 | 2024-07-01 21:59:28 |
合計ジャッジ時間 | 133,295 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
54,848 KB |
testcase_01 | AC | 45 ms
54,228 KB |
testcase_02 | AC | 45 ms
55,720 KB |
testcase_03 | AC | 47 ms
55,228 KB |
testcase_04 | AC | 202 ms
80,236 KB |
testcase_05 | AC | 191 ms
79,728 KB |
testcase_06 | AC | 185 ms
79,732 KB |
testcase_07 | AC | 186 ms
80,388 KB |
testcase_08 | AC | 186 ms
79,856 KB |
testcase_09 | AC | 1,385 ms
210,412 KB |
testcase_10 | AC | 1,388 ms
208,096 KB |
testcase_11 | AC | 1,383 ms
210,256 KB |
testcase_12 | AC | 1,369 ms
210,888 KB |
testcase_13 | AC | 1,369 ms
210,036 KB |
testcase_14 | AC | 4,277 ms
284,256 KB |
testcase_15 | AC | 4,315 ms
285,744 KB |
testcase_16 | AC | 4,347 ms
284,220 KB |
testcase_17 | AC | 4,287 ms
281,736 KB |
testcase_18 | AC | 4,326 ms
285,944 KB |
testcase_19 | AC | 4,290 ms
284,052 KB |
testcase_20 | AC | 4,295 ms
284,488 KB |
testcase_21 | AC | 4,338 ms
283,220 KB |
testcase_22 | AC | 4,312 ms
285,152 KB |
testcase_23 | AC | 4,308 ms
284,616 KB |
testcase_24 | AC | 4,310 ms
283,516 KB |
testcase_25 | AC | 4,368 ms
282,064 KB |
testcase_26 | AC | 4,371 ms
281,356 KB |
testcase_27 | AC | 4,346 ms
284,624 KB |
testcase_28 | AC | 4,335 ms
282,696 KB |
testcase_29 | AC | 4,355 ms
284,564 KB |
testcase_30 | AC | 4,339 ms
281,924 KB |
testcase_31 | AC | 4,329 ms
284,052 KB |
testcase_32 | AC | 4,354 ms
284,360 KB |
testcase_33 | AC | 4,354 ms
283,168 KB |
testcase_34 | AC | 4,320 ms
282,124 KB |
testcase_35 | AC | 4,338 ms
284,356 KB |
testcase_36 | AC | 4,309 ms
281,364 KB |
testcase_37 | AC | 4,294 ms
280,796 KB |
testcase_38 | AC | 4,295 ms
284,472 KB |
testcase_39 | AC | 1,527 ms
221,332 KB |
testcase_40 | AC | 1,621 ms
231,968 KB |
testcase_41 | AC | 2,100 ms
264,576 KB |
testcase_42 | AC | 551 ms
122,872 KB |
testcase_43 | AC | 3,972 ms
292,392 KB |
testcase_44 | AC | 4,266 ms
284,496 KB |
testcase_45 | AC | 43 ms
54,704 KB |
testcase_46 | AC | 42 ms
54,520 KB |
ソースコード
import collections mod = 998244353 def fft_inplace(a, w): n = len(a) m = n t = 1 while m >= 2: mh = m >> 1 for i in range(0, n, m): for s in range(mh): j, k = i+s, i+mh+s a[j], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k])*w[s*t] % mod m = mh t <<= 1 def ifft_inplace(a, w): n = len(a) m = 2 t = -(n >> 1) while m <= n: mh = m >> 1 for i in range(0, n, m): for s in range(mh): j, k = i+s, i+mh+s a[k] *= w[s*t] a[j], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k]) % mod m <<= 1 t //= 2 n_inv = pow(n, mod-2, mod) for i in range(n): a[i] = a[i] * n_inv % mod def zero_pad(a, n): a.extend([0] * (n - len(a))) def zero_remove(a, n): for _ in range(len(a) - n): a.pop() class Fraction: def __init__(self, num, den): self.num = num self.den = den def __add__(self, other): a_num = self.num a_den = self.den b_num = other.num b_den = other.den n2 = max(len(a_num) + len(b_num) - 1, 1) n = 1 << (n2-1).bit_length() zero_pad(a_num, n) zero_pad(a_den, n) zero_pad(b_num, n) zero_pad(b_den, n) w_root = pow(3, (mod-1)//n, mod) w = [1] * n for i in range(1, n): w[i] = w[i-1] * w_root % mod fft_inplace(a_num, w) fft_inplace(a_den, w) fft_inplace(b_num, w) fft_inplace(b_den, w) c_num = [(a * d + b * c) % mod for a, b, c, d in zip(a_num, a_den, b_num, b_den)] c_dem = [a * b % mod for a, b in zip(a_den, b_den)] ifft_inplace(c_num, w) ifft_inplace(c_dem, w) zero_remove(c_num, n) zero_remove(c_dem, n) return Fraction(c_num, c_dem) n, s = map(int, input().split()) s_inv = pow(s, mod-2, mod) p = [i * s_inv % mod for i in map(int, input().split())] fractions = collections.deque( Fraction([0, i ** 2 % mod], [1, i]) for i in p ) while len(fractions) > 1: fractions.append(fractions.popleft() + fractions.popleft()) ans = 0 factorial = 2 for i in range(1, n + 1): ans += fractions[0].num[i] * factorial % mod factorial = factorial * (i + 2) % mod ans %= mod print(ans)