結果

問題 No.195 フィボナッチ数列の理解(2)
ユーザー cielciel
提出日時 2015-12-15 02:25:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 15,340 KB
最終ジャッジ日時 2023-08-27 06:08:37
合計ジャッジ時間 3,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,192 KB
testcase_01 AC 80 ms
15,212 KB
testcase_02 AC 79 ms
15,160 KB
testcase_03 AC 78 ms
15,100 KB
testcase_04 AC 78 ms
15,300 KB
testcase_05 AC 84 ms
15,304 KB
testcase_06 AC 79 ms
15,280 KB
testcase_07 AC 76 ms
15,200 KB
testcase_08 AC 79 ms
15,088 KB
testcase_09 AC 77 ms
15,136 KB
testcase_10 AC 75 ms
15,340 KB
testcase_11 AC 79 ms
15,264 KB
testcase_12 AC 79 ms
15,128 KB
testcase_13 AC 79 ms
15,128 KB
testcase_14 AC 80 ms
15,020 KB
testcase_15 AC 78 ms
15,144 KB
testcase_16 AC 78 ms
15,204 KB
testcase_17 AC 77 ms
15,100 KB
testcase_18 AC 81 ms
15,224 KB
testcase_19 AC 81 ms
15,172 KB
testcase_20 AC 79 ms
15,020 KB
testcase_21 AC 78 ms
15,132 KB
testcase_22 AC 77 ms
15,196 KB
testcase_23 AC 78 ms
15,212 KB
testcase_24 AC 76 ms
15,016 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
F10=[1,0]
F01=[0,1]
2.upto(44){|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,_y,_z = X==Y ? Y==Z ? [1,Y,Z] : [Y,Z,X] : [X,Y,Z]
r=[Float::INFINITY,Float::INFINITY]
(0..44).each{|i|
	(0..44).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