結果
問題 | No.281 門松と魔法(1) |
ユーザー |
![]() |
提出日時 | 2022-11-14 02:21:04 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,256 bytes |
コンパイル時間 | 57 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-09-15 07:15:41 |
合計ジャッジ時間 | 6,574 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 53 WA * 4 |
コンパイルメッセージ
Main.rb:10: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:87: 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 } if D == 0 if H[0] < H[1] && H[1] > H[2] && H.size == H.uniq.size puts 0 elsif H[0] > H[1] && H[1] < H[2] && H.size == H.uniq.size puts 0 else puts -1 end exit end 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