結果

問題 No.533 Mysterious Stairs
ユーザー ei1333333ei1333333
提出日時 2017-06-23 22:47:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 498 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 158,700 KB
実行使用メモリ 60,576 KB
最終ジャッジ日時 2024-04-15 00:57:05
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
18,944 KB
testcase_01 AC 5 ms
18,840 KB
testcase_02 AC 6 ms
19,096 KB
testcase_03 AC 6 ms
18,924 KB
testcase_04 AC 6 ms
19,112 KB
testcase_05 AC 6 ms
18,776 KB
testcase_06 AC 7 ms
18,956 KB
testcase_07 AC 6 ms
18,964 KB
testcase_08 AC 6 ms
19,020 KB
testcase_09 AC 6 ms
19,060 KB
testcase_10 AC 5 ms
18,972 KB
testcase_11 AC 6 ms
18,900 KB
testcase_12 AC 6 ms
18,944 KB
testcase_13 AC 6 ms
19,040 KB
testcase_14 AC 6 ms
19,080 KB
testcase_15 AC 6 ms
19,036 KB
testcase_16 AC 6 ms
19,056 KB
testcase_17 AC 7 ms
19,280 KB
testcase_18 AC 6 ms
19,412 KB
testcase_19 AC 7 ms
19,508 KB
testcase_20 AC 14 ms
23,540 KB
testcase_21 AC 14 ms
24,212 KB
testcase_22 AC 30 ms
34,996 KB
testcase_23 AC 66 ms
60,224 KB
testcase_24 AC 67 ms
60,576 KB
testcase_25 AC 13 ms
23,744 KB
testcase_26 AC 58 ms
54,956 KB
testcase_27 AC 22 ms
29,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
int dp[1000001][4];

int rec(int idx, int pv)
{
  if(idx < 0) return (0);
  if(idx == 0) return (1);
  if(~dp[idx][pv]) return (dp[idx][pv]);
  int ret = 0;
  if(pv != 1) (ret += rec(idx - 1, 1)) %= mod;
  if(pv != 2) (ret += rec(idx - 2, 2)) %= mod;
  if(pv != 3) (ret += rec(idx - 3, 3)) %= mod;
  return (dp[idx][pv] = ret);
}

int main()
{
  int N;
  cin >> N;
  memset(dp, -1, sizeof(dp));
  cout << rec(N, 0) << endl;
}
0