結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-25 20:55:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 738 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 79,228 KB
最終ジャッジ日時 2023-09-20 10:47:56
合計ジャッジ時間 11,406 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,248 KB
testcase_01 AC 74 ms
71,564 KB
testcase_02 AC 74 ms
71,756 KB
testcase_03 AC 78 ms
71,208 KB
testcase_04 AC 728 ms
78,144 KB
testcase_05 AC 74 ms
71,416 KB
testcase_06 AC 711 ms
78,116 KB
testcase_07 AC 730 ms
79,228 KB
testcase_08 AC 683 ms
78,052 KB
testcase_09 AC 710 ms
78,148 KB
testcase_10 AC 74 ms
71,772 KB
testcase_11 AC 198 ms
78,000 KB
testcase_12 AC 73 ms
71,516 KB
testcase_13 AC 137 ms
78,036 KB
testcase_14 AC 81 ms
76,044 KB
testcase_15 AC 108 ms
78,044 KB
testcase_16 AC 85 ms
76,032 KB
testcase_17 AC 106 ms
77,992 KB
testcase_18 AC 738 ms
77,940 KB
testcase_19 AC 731 ms
77,960 KB
testcase_20 AC 714 ms
77,944 KB
testcase_21 AC 694 ms
78,220 KB
testcase_22 AC 716 ms
78,156 KB
testcase_23 AC 710 ms
78,124 KB
testcase_24 AC 695 ms
78,012 KB
権限があれば一括ダウンロードができます

ソースコード

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