結果
問題 |
No.498 ワープクリスタル (給料日編)
|
ユーザー |
|
提出日時 | 2023-02-21 16:01:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 825 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,208 KB |
実行使用メモリ | 76,380 KB |
最終ジャッジ日時 | 2024-07-22 02:56:16 |
合計ジャッジ時間 | 5,829 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
MOD = 10 ** 9 + 7 gx, gy, k = map(int, input().split()) m = 75 inv = [1 for _ in range(m + 1)] fact = [1 for _ in range(m + 1)] invfact = [1 for _ in range(m + 1)] for x in range(2, m + 1): inv[x] = (- (MOD // x) * inv[MOD % x]) % MOD fact[x] = (fact[x - 1] * x) % MOD invfact[x] = (invfact[x - 1] * inv[x]) % MOD items = [] cnt = [1] for _ in range(k): xi, yi, ni = map(int, input().split()) items.append((xi, yi, ni)) cnt.append(cnt[-1] * (ni + 1)) ans = 0 for pat in range(cnt[-1]): x = 0 y = 0 q = [] s = 0 for i in range(k): xi, yi, _ = items[i] ci = (pat % cnt[i + 1]) // cnt[i] q.append(ci) s += ci x += (ci * xi) y += (ci * yi) if x == gx and y == gy: c = fact[s] for i in range(k): c = (c * invfact[q[i]]) % MOD ans = (ans + c) % MOD print(ans)