結果

問題 No.498 ワープクリスタル (給料日編)
コンテスト
ユーザー Tawara
提出日時 2016-03-14 19:27:37
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 598 ms / 2,000 ms
コード長 883 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 262 ms
コンパイル使用メモリ 77,444 KB
最終ジャッジ日時 2025-12-03 19:49:16
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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()
0