結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー cielciel
提出日時 2015-12-15 02:04:42
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 11,424 KB
実行使用メモリ 15,388 KB
最終ジャッジ日時 2023-10-13 17:00:07
合計ジャッジ時間 2,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
15,072 KB
testcase_01 AC 74 ms
15,152 KB
testcase_02 AC 70 ms
15,164 KB
testcase_03 AC 70 ms
15,016 KB
testcase_04 AC 72 ms
15,316 KB
testcase_05 AC 73 ms
15,192 KB
testcase_06 AC 69 ms
15,252 KB
testcase_07 AC 70 ms
15,296 KB
testcase_08 AC 69 ms
15,268 KB
testcase_09 AC 72 ms
15,244 KB
testcase_10 AC 70 ms
15,088 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 69 ms
15,120 KB
testcase_19 AC 69 ms
15,268 KB
testcase_20 AC 68 ms
15,120 KB
testcase_21 WA -
testcase_22 AC 68 ms
15,116 KB
testcase_23 AC 70 ms
15,120 KB
testcase_24 AC 68 ms
14,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
F10=[1,0]
F01=[0,1]
2.upto(50){|i|
	F10[i]=F10[i-1]+F10[i-2]
	F01[i]=F01[i-1]+F01[i-2]
}
X,Y,Z=gets.split.map(&:to_i).sort
Y=1 if Y==Z
r=[Float::INFINITY,Float::INFINITY]
(0..50).each{|i|
	(0..50).each{|j|
		x=F10[i]
		y=F01[i]
		z=F10[j]
		w=F01[j]
		det=x*w-y*z
		x,y,z,w=w,-y,-z,x
		a=x*Y+y*Z
		b=z*Y+w*Z
		next if det==0
		if det<0
			det=-det
			a=-a
			b=-b
		end
		if a%det==0&&b%det==0&&a>0&&b>0
			a/=det
			b/=det
			f=[a,b]
			(2..1/0.0).each{|i|
				f[i]=f[i-1]+f[i-2]
				break if f[i]>=X
			}
			r=[r,[a,b]].min if X==1 || X==f[-1]
		end
	}
}
puts r[0].to_f.finite? ? r*' ' : -1
0