結果

問題 No.75 回数の期待値の問題
ユーザー cielciel
提出日時 2015-01-28 02:10:10
言語 PyPy2
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,150 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 77,476 KB
実行使用メモリ 268,352 KB
最終ジャッジ日時 2023-09-05 07:21:02
合計ジャッジ時間 19,271 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
82,488 KB
testcase_01 AC 142 ms
82,532 KB
testcase_02 AC 141 ms
82,488 KB
testcase_03 AC 154 ms
82,900 KB
testcase_04 AC 143 ms
82,448 KB
testcase_05 AC 145 ms
82,516 KB
testcase_06 AC 147 ms
82,516 KB
testcase_07 AC 160 ms
83,212 KB
testcase_08 AC 161 ms
82,900 KB
testcase_09 AC 169 ms
83,528 KB
testcase_10 AC 179 ms
84,576 KB
testcase_11 AC 195 ms
84,772 KB
testcase_12 AC 202 ms
84,892 KB
testcase_13 AC 209 ms
85,492 KB
testcase_14 AC 203 ms
84,740 KB
testcase_15 AC 265 ms
86,352 KB
testcase_16 AC 1,156 ms
115,284 KB
testcase_17 AC 4,434 ms
268,352 KB
testcase_18 TLE -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
#derived from checkio expected-dice

from fractions import Fraction
def gauss(a):
	if not a or len(a)==0: return None
	n=len(a)
	for i in range(n):
		if a[i][i]==0:
			for j in range(i+1,n):
				if a[j][i]!=0:
					for k in range(i,n+1): a[i][k]+=a[j][k]
					break
			else:
				return None
		for j in range(n):
			if i!=j:
				r = Fraction(a[j][i],a[i][i])
				for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r
	for i in range(n):
		x=Fraction(a[i][i],1)
		for j in range(len(a[i])):
			a[i][j] /= x
	return a

def expected(n, s, t): #, b):
	#perform probably-dice
	a=[0]*(s*(n+1)+1)
	for i in range(1,s+1):
		a[i+s]=Fraction(1,s)**n
	for e in range(n-1):
		for i in reversed(range(0,s*n+1)):
			a[i+s]=sum(a[i:i+s])
	l = t+1
	A = [[int(i==j) for i in range(l)]+[int(j!=t)] for j in range(l)]
	for start in range(l):
		if start != t:
			for roll in range(n,s*n+1):
				end = roll + start
				#end = (end + b[end%l])%l
				if end>=l: end=0
				A[start][end] -= a[roll+s]
	return float(gauss(A)[0][-1])

if __name__ == '__main__':
	import sys
	if sys.version_info[0]>=3: raw_input=input
	N=int(raw_input())
	print(expected(1,6,N))
0