結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー brthyyjpbrthyyjp
提出日時 2022-02-16 13:01:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 123,632 KB
最終ジャッジ日時 2023-09-11 17:10:44
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
92,104 KB
testcase_01 AC 121 ms
92,108 KB
testcase_02 AC 117 ms
92,340 KB
testcase_03 AC 117 ms
92,120 KB
testcase_04 AC 231 ms
95,484 KB
testcase_05 AC 120 ms
92,376 KB
testcase_06 WA -
testcase_07 AC 667 ms
123,632 KB
testcase_08 WA -
testcase_09 AC 115 ms
92,220 KB
testcase_10 AC 115 ms
92,324 KB
testcase_11 AC 174 ms
94,920 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 116 ms
92,356 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 10**6
mod = 10**9+7
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
    fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
    finv[i] = finv[i+1] * (i+1) % mod

def cmb1(n, r):
    if r <0 or r > n:
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod

from collections import defaultdict

gx, gy, k = map(int, input().split())
XYN = []
for i in range(k):
    x,y,n = map(int, input().split())
    XYN.append((x, y, n))

dp = defaultdict(lambda: 0)
dp[(0, 0, 0)] = 1
for i, (x, y, n) in enumerate(XYN):
    nx = defaultdict(lambda: 0)
    for a in range(0, n+1):
        for (cx, cy, s), v in dp.items():
            if abs(cx-gx) > 10**4*(k-i) or abs(cy-gy) > 10**4*(k-i):
                continue
            ncx, ncy = cx+a*x, cy+a*y
            ns = s+a
            nx[(ncx,ncy,ns)] += v*cmb1(ns,a)
            nx[(ncx,ncy,ns)] %= mod
    dp = nx

ans = 0
for (cx, cy, s), v in dp.items():
    if cx == gx and cy == gy:
        ans += v
        ans %= mod
print(ans)
0