結果

問題 No.533 Mysterious Stairs
ユーザー letrangerjpletrangerjp
提出日時 2017-06-23 23:54:42
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 334 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 277,344 KB
最終ジャッジ日時 2024-04-15 01:10:07
合計ジャッジ時間 14,189 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
19,232 KB
testcase_01 AC 83 ms
12,288 KB
testcase_02 AC 84 ms
12,160 KB
testcase_03 AC 76 ms
12,160 KB
testcase_04 AC 80 ms
12,416 KB
testcase_05 AC 81 ms
12,160 KB
testcase_06 AC 76 ms
12,288 KB
testcase_07 AC 75 ms
12,160 KB
testcase_08 AC 78 ms
12,288 KB
testcase_09 AC 74 ms
12,160 KB
testcase_10 AC 77 ms
12,288 KB
testcase_11 AC 80 ms
12,288 KB
testcase_12 AC 88 ms
12,160 KB
testcase_13 AC 87 ms
12,416 KB
testcase_14 AC 91 ms
12,416 KB
testcase_15 AC 93 ms
12,544 KB
testcase_16 AC 101 ms
13,056 KB
testcase_17 AC 119 ms
13,312 KB
testcase_18 AC 128 ms
14,336 KB
testcase_19 AC 153 ms
14,976 KB
testcase_20 AC 834 ms
46,124 KB
testcase_21 AC 934 ms
48,276 KB
testcase_22 AC 3,128 ms
141,832 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

$dp = Hash.new 0
def f(n)
  $dp[[0,1]] = $dp[[0,2]] = $dp[[0,3]] = 1
  (1...n).each{|i|
    $dp[[i,1]] = ($dp[[i-2,2]] + $dp[[i-3,3]]) % M
    $dp[[i,2]] = ($dp[[i-1,1]] + $dp[[i-3,3]]) % M
    $dp[[i,3]] = ($dp[[i-1,1]] + $dp[[i-2,2]]) % M
  }
  ($dp[[n-1,1]] + $dp[[n-2,2]] + $dp[[n-3,3]]) % M
end

M = 10**9+7
N = gets.to_i
p f(N)
0