結果

問題 No.115 遠足のおやつ
ユーザー fine
提出日時 2016-03-15 16:27:48
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 545 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 19,228 KB
最終ジャッジ日時 2024-10-01 06:35:47
合計ジャッジ時間 10,299 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 1 -- * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:22: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:28: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

def sol s,e,a,k,d
    if k == 0
        if a.inject(:+) == d
            return a
        else
            return nil
        end
    else
        s.upto(e){|i|
            a.push(i)
            tmp = sol(i + 1,e,a,k - 1,d)
            if tmp
                return tmp
            end
            a.pop
            }
        return nil
    end
end
n,d,k = gets.split.map(&:to_i)
if d < k * (k + 1) / 2 || d > (n * 2 - k + 1) * k / 2
    p -1
else
    tmp = sol(1,n,[],k,d)
    if tmp
        puts tmp.join(' ')
    else
        p -1
    end
end
0