結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
20,680 KB
testcase_01 AC 126 ms
20,444 KB
testcase_02 AC 127 ms
20,920 KB
testcase_03 AC 128 ms
20,184 KB
testcase_04 AC 123 ms
20,684 KB
testcase_05 AC 126 ms
20,320 KB
testcase_06 AC 133 ms
21,088 KB
testcase_07 AC 126 ms
20,840 KB
testcase_08 AC 132 ms
20,888 KB
testcase_09 AC 128 ms
21,152 KB
testcase_10 AC 131 ms
20,964 KB
testcase_11 AC 140 ms
21,536 KB
testcase_12 AC 182 ms
23,840 KB
testcase_13 AC 131 ms
20,912 KB
testcase_14 AC 132 ms
21,000 KB
testcase_15 AC 170 ms
22,104 KB
testcase_16 AC 168 ms
22,336 KB
testcase_17 AC 174 ms
22,032 KB
testcase_18 AC 180 ms
21,940 KB
testcase_19 AC 220 ms
22,852 KB
testcase_20 AC 628 ms
23,620 KB
testcase_21 AC 178 ms
22,040 KB
testcase_22 AC 169 ms
21,872 KB
testcase_23 AC 129 ms
20,848 KB
testcase_24 AC 170 ms
22,292 KB
testcase_25 AC 173 ms
21,956 KB
testcase_26 AC 154 ms
21,744 KB
testcase_27 AC 170 ms
21,856 KB
testcase_28 AC 173 ms
21,956 KB
testcase_29 AC 224 ms
23,172 KB
testcase_30 AC 521 ms
23,556 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 b!=48
	}
	p r!=0||f ? r : 9
}
0