結果
問題 | No.2788 4-33 Hard |
ユーザー | LyricalMaestro |
提出日時 | 2024-10-20 19:33:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 3,560 bytes |
コンパイル時間 | 508 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 77,188 KB |
最終ジャッジ日時 | 2024-10-20 19:33:17 |
合計ジャッジ時間 | 10,011 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
76,608 KB |
testcase_01 | AC | 89 ms
76,516 KB |
testcase_02 | AC | 102 ms
76,492 KB |
testcase_03 | AC | 143 ms
76,384 KB |
testcase_04 | AC | 101 ms
76,432 KB |
testcase_05 | AC | 139 ms
76,276 KB |
testcase_06 | AC | 100 ms
76,688 KB |
testcase_07 | AC | 90 ms
76,364 KB |
testcase_08 | AC | 93 ms
76,360 KB |
testcase_09 | AC | 109 ms
76,756 KB |
testcase_10 | AC | 136 ms
76,368 KB |
testcase_11 | AC | 124 ms
76,708 KB |
testcase_12 | AC | 127 ms
76,916 KB |
testcase_13 | AC | 127 ms
76,524 KB |
testcase_14 | AC | 125 ms
76,936 KB |
testcase_15 | AC | 125 ms
76,568 KB |
testcase_16 | AC | 126 ms
77,112 KB |
testcase_17 | AC | 126 ms
77,188 KB |
testcase_18 | AC | 144 ms
76,532 KB |
testcase_19 | AC | 130 ms
76,620 KB |
testcase_20 | AC | 127 ms
76,544 KB |
testcase_21 | AC | 122 ms
76,332 KB |
testcase_22 | AC | 121 ms
76,940 KB |
testcase_23 | AC | 124 ms
76,568 KB |
testcase_24 | AC | 129 ms
76,472 KB |
testcase_25 | AC | 121 ms
76,344 KB |
testcase_26 | AC | 126 ms
76,868 KB |
testcase_27 | AC | 143 ms
76,616 KB |
testcase_28 | AC | 124 ms
76,472 KB |
testcase_29 | AC | 121 ms
76,656 KB |
testcase_30 | AC | 125 ms
76,828 KB |
testcase_31 | AC | 138 ms
76,204 KB |
testcase_32 | AC | 141 ms
77,008 KB |
testcase_33 | AC | 136 ms
76,316 KB |
testcase_34 | AC | 135 ms
76,620 KB |
testcase_35 | AC | 161 ms
76,424 KB |
testcase_36 | AC | 139 ms
76,176 KB |
testcase_37 | AC | 142 ms
76,268 KB |
testcase_38 | AC | 138 ms
76,420 KB |
testcase_39 | AC | 139 ms
76,616 KB |
testcase_40 | AC | 140 ms
76,884 KB |
testcase_41 | AC | 139 ms
76,416 KB |
testcase_42 | AC | 143 ms
76,204 KB |
testcase_43 | AC | 168 ms
76,880 KB |
testcase_44 | AC | 138 ms
76,480 KB |
testcase_45 | AC | 137 ms
76,552 KB |
testcase_46 | AC | 139 ms
76,816 KB |
testcase_47 | AC | 137 ms
76,748 KB |
testcase_48 | AC | 135 ms
76,324 KB |
testcase_49 | AC | 136 ms
76,612 KB |
testcase_50 | AC | 133 ms
76,708 KB |
testcase_51 | AC | 159 ms
76,436 KB |
testcase_52 | AC | 139 ms
76,396 KB |
testcase_53 | AC | 135 ms
76,564 KB |
testcase_54 | AC | 137 ms
76,320 KB |
testcase_55 | AC | 138 ms
76,424 KB |
ソースコード
## https://yukicoder.me/problems/11039 MOD = 998244353 class CombinationCalculator: """ modを考慮したPermutation, Combinationを計算するためのクラス """ def __init__(self, size, mod): self.mod = mod self.factorial = [0] * (size + 1) self.factorial[0] = 1 for i in range(1, size + 1): self.factorial[i] = (i * self.factorial[i - 1]) % self.mod self.inv_factorial = [0] * (size + 1) self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod) for i in reversed(range(size)): self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod def calc_combination(self, n, r): if n < 0 or n < r or r < 0: return 0 if r == 0 or n == r: return 1 ans = self.inv_factorial[n - r] * self.inv_factorial[r] ans %= self.mod ans *= self.factorial[n] ans %= self.mod return ans def calc_permutation(self, n, r): if n < 0 or n < r: return 0 ans = self.inv_factorial[n - r] ans *= self.factorial[n] ans %= self.mod return ans def calc_combination(n, r , combi): ans = 1 if r < 0 or n < r: return 0 if r == 0 or n == r: return 1 for i in range(r): ans *= (n - i) % MOD ans %= MOD ans *= combi.inv_factorial[r] ans %= MOD return ans def main(): O = [] for _ in range(5): O.append(list(map(int, input().split()))) X = [] for _ in range(5): X.append(list(map(int, input().split()))) combi = CombinationCalculator(10, MOD) # dpをつかう dp = [[[0] * 34 for _ in range(5)] for _ in range(9)] dp[0][0][0] = 1 for a in range(5): for b in range(34): x = O[a][b] new_dp = [[[0] * 34 for _ in range(5)] for _ in range(9)] for n in range(9): for a_score in range(5): for b_score in range(34): # 拾わない new_dp[n][a_score][b_score] += dp[n][a_score][b_score] new_dp[n][a_score][b_score] %= MOD # 使う if x > 0: for m in range(1, min(8, x) + 1): a_ = a * m b_ = b * m if a_score + a_ <= 4 and b_ + b_score <= 33 and n + m <= 8: c = calc_combination(x, m, combi) new_dp[n + m][a_score + a_][b_ + b_score] += (dp[n][a_score][b_score] * c) % MOD new_dp[n + m][a_score + a_][b_ + b_score] %= MOD dp = new_dp # Xを使う answer = 0 for ao in range(5): for bo in range(34): val = dp[-1][ao][bo] for ax in range(5): for bx in range(34): if ax + ao == 4 and bx + bo == 33: if bx == 0: answer += (val * X[ax][bx]) % MOD answer %= MOD else: if ax + ao >= bx + bo - 4: answer += (val * X[ax][bx]) % MOD answer %= MOD print(answer) if __name__ == "__main__": main()