結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
15,236 KB
testcase_01 AC 71 ms
15,296 KB
testcase_02 AC 69 ms
14,980 KB
testcase_03 AC 73 ms
15,244 KB
testcase_04 AC 72 ms
15,272 KB
testcase_05 AC 69 ms
15,340 KB
testcase_06 AC 70 ms
15,092 KB
testcase_07 AC 73 ms
15,236 KB
testcase_08 AC 70 ms
15,120 KB
testcase_09 AC 71 ms
15,296 KB
testcase_10 AC 70 ms
15,240 KB
testcase_11 WA -
testcase_12 AC 71 ms
14,980 KB
testcase_13 AC 69 ms
15,296 KB
testcase_14 AC 68 ms
15,200 KB
testcase_15 AC 69 ms
15,224 KB
testcase_16 AC 69 ms
15,148 KB
testcase_17 AC 69 ms
15,084 KB
testcase_18 AC 71 ms
15,156 KB
testcase_19 AC 70 ms
15,216 KB
testcase_20 AC 71 ms
15,152 KB
testcase_21 AC 69 ms
15,128 KB
testcase_22 AC 70 ms
15,016 KB
testcase_23 AC 68 ms
15,304 KB
testcase_24 AC 70 ms
14,980 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]
			if f.include?(X) || lambda{
				(2..1/0.0).each{|i|
					f[i]=f[i-1]+f[i-2]
					break if f[i]>=X
				}
				X==f[-1]
			}.call
				r=[r,[a,b]].min
			end
		end
	}
}
puts r[0].to_f.finite? ? r*' ' : -1
0