結果

問題 No.434 占い
ユーザー cielciel
提出日時 2016-10-17 21:09:30
言語 Ruby
(3.2.2)
結果
AC  
実行時間 652 ms / 2,000 ms
コード長 432 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 11,464 KB
実行使用メモリ 23,788 KB
最終ジャッジ日時 2023-08-27 02:09:55
合計ジャッジ時間 8,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
20,404 KB
testcase_01 AC 141 ms
20,388 KB
testcase_02 AC 128 ms
20,604 KB
testcase_03 AC 129 ms
20,956 KB
testcase_04 AC 130 ms
20,544 KB
testcase_05 AC 127 ms
20,564 KB
testcase_06 AC 133 ms
21,328 KB
testcase_07 AC 127 ms
20,456 KB
testcase_08 AC 135 ms
20,964 KB
testcase_09 AC 130 ms
20,876 KB
testcase_10 AC 132 ms
21,324 KB
testcase_11 AC 137 ms
21,432 KB
testcase_12 AC 180 ms
23,788 KB
testcase_13 AC 131 ms
20,968 KB
testcase_14 AC 131 ms
20,764 KB
testcase_15 AC 169 ms
22,012 KB
testcase_16 AC 170 ms
22,016 KB
testcase_17 AC 165 ms
22,016 KB
testcase_18 AC 172 ms
22,252 KB
testcase_19 AC 217 ms
22,676 KB
testcase_20 AC 652 ms
23,700 KB
testcase_21 AC 166 ms
22,452 KB
testcase_22 AC 172 ms
21,904 KB
testcase_23 AC 130 ms
20,264 KB
testcase_24 AC 177 ms
22,260 KB
testcase_25 AC 180 ms
22,436 KB
testcase_26 AC 152 ms
21,936 KB
testcase_27 AC 175 ms
22,036 KB
testcase_28 AC 181 ms
21,916 KB
testcase_29 AC 238 ms
23,124 KB
testcase_30 AC 549 ms
23,616 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
	s=gets.chomp
	s.each_byte.with_index{|b,i|r=(r+(b-48)*comb(s.size-1,i))%9}
	p r!=0||s.each_byte.all?{|b|b==48} ? r : 9
}
0