結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,396 KB
testcase_01 AC 83 ms
15,344 KB
testcase_02 AC 83 ms
15,288 KB
testcase_03 AC 85 ms
15,264 KB
testcase_04 AC 81 ms
15,356 KB
testcase_05 AC 196 ms
15,452 KB
testcase_06 AC 237 ms
16,396 KB
testcase_07 AC 295 ms
16,112 KB
testcase_08 AC 88 ms
15,196 KB
testcase_09 AC 82 ms
15,192 KB
testcase_10 AC 260 ms
16,388 KB
testcase_11 AC 85 ms
15,360 KB
testcase_12 AC 278 ms
16,880 KB
testcase_13 AC 107 ms
15,284 KB
testcase_14 TLE -
testcase_15 AC 82 ms
15,368 KB
testcase_16 AC 82 ms
15,372 KB
testcase_17 AC 83 ms
15,300 KB
testcase_18 AC 85 ms
15,380 KB
testcase_19 AC 86 ms
15,316 KB
testcase_20 AC 106 ms
15,368 KB
testcase_21 AC 85 ms
15,188 KB
testcase_22 AC 83 ms
15,312 KB
testcase_23 AC 83 ms
15,324 KB
testcase_24 AC 83 ms
15,296 KB
testcase_25 AC 83 ms
15,352 KB
testcase_26 AC 86 ms
15,056 KB
testcase_27 AC 83 ms
15,352 KB
testcase_28 AC 82 ms
15,156 KB
testcase_29 AC 83 ms
15,292 KB
testcase_30 AC 85 ms
15,432 KB
testcase_31 AC 83 ms
15,152 KB
testcase_32 AC 83 ms
15,268 KB
testcase_33 AC 808 ms
19,044 KB
testcase_34 AC 85 ms
15,280 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
        z = xs[i]
        if z[0] > d
            t << [i+1,d,p]
            next
        end
        next if z[1] < d
        t << [i + 1, d, p]
        t << [i + 1, d - z[0], 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