結果
| 問題 | No.320 眠れない夜に |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-05 20:12:57 |
| 言語 | Ruby (4.0.6 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 51 ms / 2,000 ms |
| + 602µs | |
| コード長 | 418 bytes |
| 記録 | |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 8,832 KB |
| 実行使用メモリ | 14,592 KB |
| 最終ジャッジ日時 | 2026-09-09 22:43:42 |
| 合計ジャッジ時間 | 4,473 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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