結果
問題 |
No.498 ワープクリスタル (給料日編)
|
ユーザー |
|
提出日時 | 2022-07-27 22:47:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 530 ms / 2,000 ms |
コード長 | 1,482 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 241,108 KB |
最終ジャッジ日時 | 2024-07-17 12:07:18 |
合計ジャッジ時間 | 8,030 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
class NCK: ''' 最大値 :N mod ''' def __init__(self,N,mod): self.mod = mod self.N = N self.factmod = [1,1] for i in range(2,self.N+1): self.factmod.append((self.factmod[-1]*i)%self.mod) self.inv = [0,1] for i in range(2, N + 1): self.inv.append((-self.inv[self.mod % i] * (self.mod // i)) % self.mod) self.invfact = [1,1] for i in range(2, N + 1): self.invfact.append((self.invfact[-1]*self.inv[i])%self.mod) def nCk(self,a,b): if a < b: return 0 return ((self.factmod[a]*self.invfact[b]%self.mod)*self.invfact[a-b])%self.mod def invnCk(self,a,b): return ((self.factmod[a-b]*self.invfact[a]%self.mod)*self.factmod[b])%self.mod Gx,Gy,K = map(int,input().split()) mod = 10**9+7 lsxy = [] lsN = [] for i in range(K): x,y,N = map(int,input().split()) lsxy.append((x,y)) lsN.append(N) ll = [] def func(i,ls): if i == K: ll.append(ls[:]) return lsp = ls[:] for j in range(lsN[i]+1): func(i+1, lsp+[j]) func(0, []) ans = 0 nck = NCK(1000, 10**9+7) for ls in ll: x,y = 0,0 for i in range(K): x += ls[i]*lsxy[i][0] y += ls[i]*lsxy[i][1] if x == Gx and y == Gy: cnt = 1 cnt *= nck.factmod[sum(ls)] for j in ls: cnt *= nck.invfact[j] cnt %= mod ans += cnt ans %= mod print(ans)