結果
問題 | No.281 門松と魔法(1) |
ユーザー |
![]() |
提出日時 | 2022-11-14 02:17:48 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,069 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-09-15 07:13:48 |
合計ジャッジ時間 | 6,748 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 WA * 4 RE * 8 |
コンパイルメッセージ
Main.rb:75: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
D = gets.to_i H = 3.times.map { gets.to_i } def f(h) cnt = 0 if h[0] == h[2] h[0] = [0, h[0] - D].max cnt += 1 end if h[0] == h[2] return Float::INFINITY end if h[0] <= h[1] diff = h[1] - h[0] + 1 c = Rational(diff, D).ceil cnt += c h[1] = [0, h[1] - c * D].max end if h[2] <= h[1] diff = h[2] - h[0] + 1 c = Rational(diff, D).ceil cnt += c h[2] = [0, h[2] - c * D].max end if h[0] == h[1] return Float::INFINITY end if h[1] == h[2] return Float::INFINITY end cnt end def g(h) cnt = 0 if h[0] >= h[1] diff = h[0] - h[1] + 1 c = Rational(diff, D).ceil cnt += c h[0] = [0, h[1] - c * D].max end if h[2] >= h[1] diff = h[2] - h[1] + 1 c = Rational(diff, D).ceil cnt += c h[2] = [0, h[2] - c * D].max end if h[0] == h[2] h[0] = [0, h[0] - D].max cnt += 1 end if h[0] == h[2] return Float::INFINITY end cnt end a1 = f(H.dup) a2 = g(H.dup) ans = [a1, a2].min if ans == Float::INFINITY puts -1 else puts ans end