結果
問題 | No.2499 Sum of Products of Sums |
ユーザー | KumaTachiRen |
提出日時 | 2023-09-18 17:14:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 494 ms / 2,000 ms |
コード長 | 2,401 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,436 KB |
実行使用メモリ | 78,948 KB |
最終ジャッジ日時 | 2024-07-05 07:23:07 |
合計ジャッジ時間 | 4,461 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
59,668 KB |
testcase_01 | AC | 38 ms
59,516 KB |
testcase_02 | AC | 77 ms
76,936 KB |
testcase_03 | AC | 38 ms
59,488 KB |
testcase_04 | AC | 39 ms
60,084 KB |
testcase_05 | AC | 38 ms
59,380 KB |
testcase_06 | AC | 37 ms
60,432 KB |
testcase_07 | AC | 69 ms
76,440 KB |
testcase_08 | AC | 70 ms
76,804 KB |
testcase_09 | AC | 71 ms
76,460 KB |
testcase_10 | AC | 67 ms
74,620 KB |
testcase_11 | AC | 69 ms
76,572 KB |
testcase_12 | AC | 69 ms
76,248 KB |
testcase_13 | AC | 336 ms
78,308 KB |
testcase_14 | AC | 315 ms
77,784 KB |
testcase_15 | AC | 309 ms
78,084 KB |
testcase_16 | AC | 352 ms
78,564 KB |
testcase_17 | AC | 491 ms
78,916 KB |
testcase_18 | AC | 494 ms
78,784 KB |
testcase_19 | AC | 491 ms
78,948 KB |
ソースコード
MOD = 998244353 K, M, W = 119, 23, 31 # https://qiita.com/izu_nori/items/1c5cdef0500ffa0276f5 class NTT: def __init__(self): self.ws = [pow(W, 2**i, MOD) for i in range(M, -1, -1)] self.iws = [pow(w, MOD - 2, MOD) for w in self.ws] def convolution(self, f, g): nf = len(f) ng = len(g) m = nf + ng - 1 n = 2 ** (m - 1).bit_length() f = [x % MOD for x in f] + [0] * (n - nf) g = [x % MOD for x in g] + [0] * (n - ng) self.ntt(f) self.ntt(g) for i in range(n): f[i] = f[i] * g[i] % MOD self.intt(f) return f[:m] def ntt(self, A): if len(A) == 1: return n = len(A) k = n.bit_length() - 1 r = 1 << (k - 1) for w in self.ws[k:0:-1]: for l in range(0, n, 2 * r): wi = 1 for i in range(r): A[l + i], A[l + i + r] = (A[l + i] + A[l + i + r]) % MOD, (A[l + i] - A[l + i + r]) * wi % MOD wi = wi * w % MOD r = r // 2 def intt(self, A): if len(A) == 1: return n = len(A) k = (n - 1).bit_length() r = 1 for w in self.iws[1 : k + 1]: for l in range(0, n, 2 * r): wi = 1 for i in range(r): A[l + i], A[l + i + r] = (A[l + i] + A[l + i + r] * wi) % MOD, (A[l + i] - A[l + i + r] * wi) % MOD wi = wi * w % MOD r = r * 2 ni = pow(n, MOD - 2, MOD) for i in range(n): A[i] = A[i] * ni % MOD FACT_SIZE = 3000 fact = [1] * FACT_SIZE for i in range(1, FACT_SIZE): fact[i] = fact[i - 1] * i % MOD ifact = [1] * FACT_SIZE ifact[FACT_SIZE - 1] = pow(fact[FACT_SIZE - 1], MOD - 2, MOD) for i in range(FACT_SIZE - 1, 0, -1): ifact[i - 1] = ifact[i] * i % MOD h, w = map(int, input().split(" ")) f = [fact[w]] ntt = NTT() for _ in range(h): a, b = map(int, input().split(" ")) a -= 1 g = [0] * (w + 1) ff_a, ff_b = 1, 1 for n in range(w): ff_a = ff_a * (w + a - n) % MOD ff_b = ff_b * (w + b - n) % MOD for n in range(w + 1): g[n] = ifact[n] * ifact[w + n] % MOD * (ff_b - ff_a) % MOD ff_a = ff_a * (a - n) % MOD ff_b = ff_b * (b - n) % MOD f = ntt.convolution(f, g)[: w + 1] print(f[w])