結果

問題 No.434 占い
ユーザー cielciel
提出日時 2016-10-17 21:13:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-05-02 03:14:09
合計ジャッジ時間 6,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
17,536 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 129 ms
17,792 KB
testcase_05 AC 129 ms
17,664 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 138 ms
18,176 KB
testcase_09 AC 137 ms
18,176 KB
testcase_10 AC 139 ms
18,176 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 136 ms
18,304 KB
testcase_14 AC 135 ms
18,048 KB
testcase_15 AC 184 ms
18,944 KB
testcase_16 AC 192 ms
19,456 KB
testcase_17 AC 187 ms
19,712 KB
testcase_18 AC 189 ms
19,712 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 179 ms
19,072 KB
testcase_22 AC 185 ms
19,456 KB
testcase_23 AC 136 ms
17,792 KB
testcase_24 AC 180 ms
18,816 KB
testcase_25 AC 184 ms
19,584 KB
testcase_26 AC 159 ms
19,328 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:30: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
I=[nil,1,5,nil,7,2,nil,4,8]
def z(n)
	r=0
	while n%3==0
		r+=1
		n/=3
	end
	[n,r]
end
def comb(n,k)
	k0,z0=F[n]
	k1,z1=F[k]
	k2,z2=F[n-k]
	z=z0-z1-z2
	r=k0*I[k1]*I[k2]%9
	[r,r*3%9][z]||0
end

F=[[1,0]]
(1..100000).each{|i|
	k0,z0=F[i-1]
	k1,z1=z(i)
	F[i]=[k0*k1%9,z0+z1]
}
gets.to_i.times{
	r=0
	f=true
	s=gets.chomp
	n=s.size
	s.each_byte.with_index{|b,i|
		r=(r+(b-48)*comb(s.size-1,i))%9
		f=false if r!=0
	}
	p r!=0||f ? r : 9
}
0