結果

問題 No.320 眠れない夜に
ユーザー LeonardoneLeonardone
提出日時 2015-12-13 08:29:00
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 906 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 11,484 KB
実行使用メモリ 32,908 KB
最終ジャッジ日時 2023-10-13 14:48:31
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,236 KB
testcase_01 AC 82 ms
15,060 KB
testcase_02 AC 86 ms
15,284 KB
testcase_03 AC 86 ms
15,304 KB
testcase_04 AC 85 ms
15,056 KB
testcase_05 AC 193 ms
15,724 KB
testcase_06 AC 237 ms
16,316 KB
testcase_07 AC 296 ms
16,216 KB
testcase_08 AC 90 ms
15,308 KB
testcase_09 AC 84 ms
15,056 KB
testcase_10 AC 255 ms
16,504 KB
testcase_11 AC 86 ms
15,400 KB
testcase_12 AC 273 ms
16,824 KB
testcase_13 AC 108 ms
15,360 KB
testcase_14 TLE -
testcase_15 AC 84 ms
15,228 KB
testcase_16 AC 81 ms
15,360 KB
testcase_17 AC 82 ms
15,284 KB
testcase_18 AC 80 ms
15,140 KB
testcase_19 AC 82 ms
15,200 KB
testcase_20 AC 105 ms
15,404 KB
testcase_21 AC 83 ms
15,132 KB
testcase_22 AC 81 ms
15,248 KB
testcase_23 AC 81 ms
15,244 KB
testcase_24 AC 83 ms
15,036 KB
testcase_25 AC 81 ms
15,200 KB
testcase_26 AC 83 ms
15,260 KB
testcase_27 AC 84 ms
15,140 KB
testcase_28 AC 82 ms
15,240 KB
testcase_29 AC 82 ms
15,148 KB
testcase_30 AC 81 ms
15,188 KB
testcase_31 AC 82 ms
15,244 KB
testcase_32 AC 81 ms
15,052 KB
testcase_33 AC 776 ms
18,740 KB
testcase_34 AC 82 ms
15,164 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)
    n = xs.size - 1
    t = [[i,d,p]]
    r = []
    while !t.empty?
        i, d, p = t.pop
        if d == 0
            r << p
            next
        end
        next if i > n
        x, s = xs[i]
        if x > d
            t << [i+1,d,p]
            next
        end
        next if s < d
        t << [i + 1, d, p]
        t << [i + 1, d - x, p + 1]
    end
    r.empty? ? - 1 : r.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