結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー rpy3cpp
提出日時 2017-03-25 20:55:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 668 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 79,100 KB
最終ジャッジ日時 2024-07-06 06:15:37
合計ジャッジ時間 7,987 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import math

def read_data():
    Gx, Gy, K = map(int, input().split())
    xs = []
    ys = []
    Ns = []
    for k in range(K):
        x, y, N = map(int, input().split())
        xs.append(x)
        ys.append(y)
        Ns.append(N)
    return Gx, Gy, K, xs, ys, Ns

def solve(Gx, Gy, K, xs, ys, Ns):
    mod = 10**9 + 7
    counts = 0
    patterns = [range(n + 1) for n in Ns]
    for ns in itertools.product(*patterns):
        X = sum(n * x for n, x in zip(ns, xs))
        Y = sum(n * y for n, y in zip(ns, ys))
        if X == Gx and Y == Gy:
            counts += count_patterns(ns, mod)
            counts %= mod
    return counts

def count_patterns(ns, mod):
    num = math.factorial(sum(ns))
    for n in ns:
        num //= math.factorial(n)
    return num % mod
    

Gx, Gy, K, xs, ys, Ns = read_data()
print(solve(Gx, Gy, K, xs, ys, Ns))
0