結果

問題 No.434 占い
ユーザー cielciel
提出日時 2016-10-17 21:20:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 460 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 23,984 KB
最終ジャッジ日時 2023-08-27 06:38:19
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
20,364 KB
testcase_01 AC 126 ms
20,936 KB
testcase_02 AC 125 ms
20,528 KB
testcase_03 AC 128 ms
20,744 KB
testcase_04 AC 122 ms
20,280 KB
testcase_05 AC 121 ms
20,680 KB
testcase_06 AC 130 ms
21,200 KB
testcase_07 AC 123 ms
20,908 KB
testcase_08 AC 120 ms
20,392 KB
testcase_09 AC 121 ms
20,688 KB
testcase_10 AC 122 ms
20,340 KB
testcase_11 AC 129 ms
21,064 KB
testcase_12 AC 168 ms
23,984 KB
testcase_13 AC 123 ms
20,932 KB
testcase_14 AC 123 ms
20,936 KB
testcase_15 AC 156 ms
20,676 KB
testcase_16 AC 160 ms
20,716 KB
testcase_17 AC 162 ms
20,560 KB
testcase_18 AC 169 ms
21,124 KB
testcase_19 AC 210 ms
23,748 KB
testcase_20 AC 567 ms
23,940 KB
testcase_21 AC 157 ms
20,536 KB
testcase_22 AC 159 ms
20,904 KB
testcase_23 AC 123 ms
20,600 KB
testcase_24 AC 153 ms
20,864 KB
testcase_25 AC 152 ms
20,688 KB
testcase_26 AC 139 ms
20,304 KB
testcase_27 AC 163 ms
21,172 KB
testcase_28 AC 153 ms
21,156 KB
testcase_29 AC 228 ms
23,848 KB
testcase_30 AC 505 ms
23,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: 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
	r*3**z%9
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 b!=48
	}
	p r!=0||f ? r : 9
}
0