結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー TawaraTawara
提出日時 2016-03-14 19:27:37
言語 Python2
(2.7.18)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 239,580 KB
最終ジャッジ日時 2024-04-23 18:56:11
合計ジャッジ時間 8,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,816 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 9 ms
6,944 KB
testcase_03 AC 9 ms
6,944 KB
testcase_04 AC 533 ms
209,740 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 AC 610 ms
239,492 KB
testcase_07 AC 550 ms
210,468 KB
testcase_08 AC 609 ms
239,516 KB
testcase_09 AC 599 ms
239,396 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 194 ms
45,560 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 36 ms
15,856 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 12 ms
7,040 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 11 ms
7,040 KB
testcase_18 AC 604 ms
239,424 KB
testcase_19 AC 623 ms
239,580 KB
testcase_20 AC 610 ms
239,544 KB
testcase_21 AC 605 ms
239,556 KB
testcase_22 AC 622 ms
239,540 KB
testcase_23 AC 598 ms
239,396 KB
testcase_24 AC 610 ms
239,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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