結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー TawaraTawara
提出日時 2016-03-15 10:08:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 904 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 66,688 KB
最終ジャッジ日時 2024-10-15 19:44:29
合計ジャッジ時間 12,854 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,288 KB
testcase_01 AC 76 ms
12,160 KB
testcase_02 AC 83 ms
12,160 KB
testcase_03 AC 83 ms
12,160 KB
testcase_04 AC 877 ms
66,432 KB
testcase_05 AC 84 ms
12,160 KB
testcase_06 AC 861 ms
66,560 KB
testcase_07 AC 904 ms
66,688 KB
testcase_08 AC 852 ms
66,304 KB
testcase_09 AC 868 ms
66,560 KB
testcase_10 AC 82 ms
12,032 KB
testcase_11 AC 363 ms
28,800 KB
testcase_12 AC 85 ms
12,160 KB
testcase_13 AC 272 ms
21,888 KB
testcase_14 AC 80 ms
12,416 KB
testcase_15 AC 93 ms
12,416 KB
testcase_16 AC 79 ms
12,032 KB
testcase_17 AC 87 ms
12,672 KB
testcase_18 AC 851 ms
66,432 KB
testcase_19 AC 863 ms
66,432 KB
testcase_20 AC 877 ms
66,432 KB
testcase_21 AC 848 ms
66,432 KB
testcase_22 AC 841 ms
66,304 KB
testcase_23 AC 846 ms
66,304 KB
testcase_24 AC 858 ms
66,560 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

p = 10**9+7
comb = Array.new(76){[0]*76}
comb[0][0] = 1
Gx,Gy,K = gets.split().map{|s| s.to_i}
(0..K*15-1).each{|i|
	(0..i+1).each{|j|
		if j > 0 then
			comb[i+1][j] = (comb[i][j] + comb[i][j-1]) % p
		else
			comb[i+1][j] = comb[i][j]
		end
	}
}
G = [Gx,Gy]; dp = [nil]*(1<<K*4); dp[0] = [0,0]
(0..K-1).each{|i|
	x,y,n = gets.split().map{|s| s.to_i}
	shift = i*4
	j = 0
	while n > 0
		mul = [1<<j,n].min()
		mx,my = x*mul,y*mul
		n -= mul
		(0..(1<<(j+shift))-1).reverse_each{|k|
			if dp[k] == nil then
				next
			end
			dp[k+(mul<<shift)]=[dp[k][0]+mx,dp[k][1]+my]
		}
		j += 1
	end
}
ans = 0
(0..(1<<(K*4))-1).each{|k|
	if dp[k] != G then
		next
	end
	total = 0
	tmp = 1
	(0..K-1).each{|i| total += (k>>(i*4))%16}
	(0..K-1).each{|i|
		dup_n = (k>>(i*4))%16;
		tmp = tmp * comb[total][dup_n] % p;
		total-=dup_n;
	}
	ans = (ans + tmp) % p;
}
p ans
0