結果

問題 No.320 眠れない夜に
ユーザー LeonardoneLeonardone
提出日時 2015-12-13 08:18:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,305 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2023-10-13 14:48:20
合計ジャッジ時間 6,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,196 KB
testcase_01 AC 81 ms
15,360 KB
testcase_02 AC 83 ms
15,276 KB
testcase_03 AC 81 ms
15,308 KB
testcase_04 AC 81 ms
15,160 KB
testcase_05 AC 132 ms
15,344 KB
testcase_06 AC 146 ms
15,288 KB
testcase_07 AC 174 ms
15,280 KB
testcase_08 AC 83 ms
15,068 KB
testcase_09 AC 79 ms
15,196 KB
testcase_10 AC 156 ms
15,056 KB
testcase_11 AC 83 ms
15,264 KB
testcase_12 AC 166 ms
15,156 KB
testcase_13 AC 91 ms
15,224 KB
testcase_14 AC 1,305 ms
15,276 KB
testcase_15 AC 81 ms
15,164 KB
testcase_16 AC 81 ms
15,244 KB
testcase_17 AC 80 ms
15,060 KB
testcase_18 AC 82 ms
15,232 KB
testcase_19 AC 81 ms
15,060 KB
testcase_20 AC 90 ms
15,240 KB
testcase_21 AC 82 ms
15,236 KB
testcase_22 AC 82 ms
15,232 KB
testcase_23 AC 80 ms
15,256 KB
testcase_24 AC 81 ms
15,060 KB
testcase_25 AC 81 ms
15,160 KB
testcase_26 AC 82 ms
15,152 KB
testcase_27 AC 80 ms
15,064 KB
testcase_28 AC 80 ms
15,164 KB
testcase_29 AC 80 ms
15,312 KB
testcase_30 AC 81 ms
15,340 KB
testcase_31 AC 81 ms
15,160 KB
testcase_32 AC 82 ms
15,136 KB
testcase_33 AC 383 ms
15,228 KB
testcase_34 AC 81 ms
15,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gs(); gets.chomp; end
def gi(); gets.to_i; end
def gss(); gets.chomp.split; end
def gis(); gss.map(&:to_i); end

N, M = gis

def rec(xs,i,d,p)
    return p if d == 0
    return -1 if i >= xs.size
    x, s = xs[i]
    return -1 if s < d
    return rec(xs,i+1,d,p) if x > d
    r1 = rec(xs,i+1,d,p)
    r2 = rec(xs,i+1,d-x,p+1)
    return r2 if r1 < 0
    return r1 if r2 < 0
    [r1, r2].min
end

def fibs(n)
    f = [1, 1]
    (2...n).each do |i|
        f << f[i - 1] + f[i - 2]
    end
    fs = [[1,1]]
    (1...f.size).each do |i|
        fs << [f[i], f[i] + fs[i-1][1]]
    end
    fs.reverse
end

def solve(n,m)
    f = fibs(n)
    rec(f[2..-1], 0, f[0][0] - m, 0)
end

p solve(N,M)

0