結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
15,292 KB
testcase_01 AC 70 ms
15,324 KB
testcase_02 AC 71 ms
15,224 KB
testcase_03 AC 77 ms
15,336 KB
testcase_04 AC 79 ms
15,216 KB
testcase_05 AC 75 ms
15,308 KB
testcase_06 AC 73 ms
15,220 KB
testcase_07 AC 72 ms
15,248 KB
testcase_08 AC 73 ms
15,160 KB
testcase_09 AC 68 ms
15,000 KB
testcase_10 AC 72 ms
15,332 KB
testcase_11 AC 71 ms
15,156 KB
testcase_12 AC 71 ms
15,288 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 68 ms
15,128 KB
testcase_16 AC 67 ms
15,124 KB
testcase_17 AC 68 ms
15,328 KB
testcase_18 AC 68 ms
15,000 KB
testcase_19 AC 70 ms
15,340 KB
testcase_20 AC 70 ms
15,228 KB
testcase_21 AC 68 ms
15,124 KB
testcase_22 AC 68 ms
15,120 KB
testcase_23 AC 70 ms
15,192 KB
testcase_24 AC 69 ms
14,996 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
X=1 if X==Y
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*X+y*Y
		b=z*X+w*Y
		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?(Z) || lambda{
				(2..1/0.0).each{|i|
					f[i]=f[i-1]+f[i-2]
					break if f[i]>=Z
				}
				Z==f[-1]
			}.call
				r=[r,[a,b]].min
			end
		end
	}
}
puts r[0].to_f.finite? ? r*' ' : -1
0