結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,032 KB
testcase_01 AC 76 ms
12,160 KB
testcase_02 AC 78 ms
12,288 KB
testcase_03 AC 78 ms
12,288 KB
testcase_04 AC 859 ms
66,304 KB
testcase_05 AC 78 ms
12,160 KB
testcase_06 AC 840 ms
66,432 KB
testcase_07 AC 836 ms
66,560 KB
testcase_08 AC 839 ms
66,432 KB
testcase_09 AC 841 ms
66,432 KB
testcase_10 AC 75 ms
12,160 KB
testcase_11 AC 369 ms
27,648 KB
testcase_12 AC 77 ms
12,160 KB
testcase_13 AC 258 ms
21,760 KB
testcase_14 AC 78 ms
12,288 KB
testcase_15 AC 91 ms
12,672 KB
testcase_16 AC 76 ms
12,288 KB
testcase_17 AC 86 ms
12,544 KB
testcase_18 AC 846 ms
66,560 KB
testcase_19 AC 841 ms
66,432 KB
testcase_20 AC 845 ms
66,560 KB
testcase_21 AC 828 ms
66,560 KB
testcase_22 AC 856 ms
66,432 KB
testcase_23 AC 843 ms
66,560 KB
testcase_24 AC 833 ms
66,432 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