結果
問題 |
No.498 ワープクリスタル (給料日編)
|
ユーザー |
![]() |
提出日時 | 2016-03-14 19:27:37 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 750 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 876 ms |
コンパイル使用メモリ | 7,080 KB |
実行使用メモリ | 239,680 KB |
最終ジャッジ日時 | 2024-10-15 19:43:44 |
合計ジャッジ時間 | 10,332 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
from math import log def solve(): p = 10**9+7 F = [1]; FI = [0]*16 for i in xrange(75): F.append((i+1)*F[i]%p) FI[15] = pow(F[15],p-2,p) for i in xrange(15,0,-1): FI[i-1] = i*FI[i]%p Gx,Gy,K = map(int,raw_input().split()) G = (Gx,Gy); dp = {0:(0,0)} for i in xrange(K): x,y,N = map(int,raw_input().split()) mul = 1; shift = i*4 for j in xrange(int(log(N,2))): ndp = dict(); mx,my = x*mul,y*mul for k,h in dp.iteritems(): ndp[k] = h; ndp[k+(mul<<shift)]=(h[0]+mx,h[1]+my) dp = ndp; N -= mul; mul *= 2 if N > 0: ndp = dict(); mx,my = x*N,y*N for k,h in dp.iteritems(): ndp[k] = h; ndp[k+(N<<shift)]=(h[0]+mx,h[1]+my) dp = ndp ans = 0 for k,v in dp.iteritems(): if v != G:continue total = 0; deno = 1 for j in xrange(K): dup_n = k%16; k>>=4 total += dup_n; deno=deno*FI[dup_n]%p ans = (ans + F[total]*deno)%p print ans solve()