結果
| 問題 | No.320 眠れない夜に |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-05 20:12:57 |
| 言語 | Ruby (4.0.2) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 418 bytes |
| 記録 | |
| コンパイル時間 | 306 ms |
| コンパイル使用メモリ | 8,832 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-04-20 00:44:49 |
| 合計ジャッジ時間 | 5,506 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
コンパイルメッセージ
Main.rb:10: warning: ambiguous first argument; put parentheses or a space even after `-` operator Main.rb:27: warning: ambiguous first argument; put parentheses or a space even after `-` operator Syntax OK
ソースコード
n,m = gets.split.map(&:to_i)
dp = Array.new(n + 1)
dp[0] = 0
dp[1] = 1
2.upto(n){|i|
dp[i] = dp[i - 1] + dp[i - 2]
}
x = dp[n] - m
if x < 0
p -1
elsif x == 0
p 0
else
ans = 0
(n - 2).downto(1){|i|
if x >= dp[i]
x -= dp[i]
ans += 1
end
if x == 0
break
end
}
if x == 0
p ans
else
p -1
end
end