結果

問題 No.660 家を通り過ぎないランダムウォーク問題
コンテスト
ユーザー cympfh
提出日時 2018-03-02 23:34:44
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 391 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 186 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 50,856 KB
最終ジャッジ日時 2026-03-06 17:55:08
合計ジャッジ時間 57,560 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 8 TLE * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

def f(n)
  m = 2 * n
  ans = 0
  xs={}
  xs[0]=1
  m.times do
    ys = {}
    xs.keys.each do |x|
      if ys[x-1] == nil
        ys[x-1] = xs[x]
      else
        ys[x-1] += xs[x]
      end
      if ys[x+1] == nil
        ys[x+1] = xs[x]
      else
        ys[x+1] += xs[x]
      end
    end
    ans += ys[n] if ys[n] != nil
    xs = ys.clone
    xs[n] = 0
  end
  ans
end

p f(gets.to_i)
0