結果

問題 No.533 Mysterious Stairs
ユーザー Akihiro ShojiAkihiro Shoji
提出日時 2017-06-25 16:08:08
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 612 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 86,168 KB
実行使用メモリ 106,928 KB
最終ジャッジ日時 2023-09-03 14:47:14
合計ジャッジ時間 3,634 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
33,972 KB
testcase_01 AC 22 ms
33,988 KB
testcase_02 AC 23 ms
33,984 KB
testcase_03 AC 23 ms
34,016 KB
testcase_04 AC 22 ms
33,980 KB
testcase_05 AC 22 ms
33,964 KB
testcase_06 AC 23 ms
34,044 KB
testcase_07 AC 22 ms
33,960 KB
testcase_08 AC 21 ms
34,000 KB
testcase_09 AC 22 ms
33,984 KB
testcase_10 AC 22 ms
34,048 KB
testcase_11 AC 22 ms
34,004 KB
testcase_12 AC 23 ms
34,068 KB
testcase_13 AC 22 ms
34,076 KB
testcase_14 AC 23 ms
34,020 KB
testcase_15 AC 23 ms
34,016 KB
testcase_16 AC 23 ms
34,268 KB
testcase_17 AC 25 ms
34,368 KB
testcase_18 AC 24 ms
34,560 KB
testcase_19 AC 25 ms
34,704 KB
testcase_20 AC 45 ms
42,112 KB
testcase_21 AC 48 ms
42,956 KB
testcase_22 AC 100 ms
61,880 KB
testcase_23 AC 221 ms
105,996 KB
testcase_24 AC 224 ms
106,928 KB
testcase_25 AC 44 ms
42,116 KB
testcase_26 AC 197 ms
96,788 KB
testcase_27 AC 75 ms
52,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

ulong INF = ulong.max;
ulong M = 10L^^9 + 7;
ulong[4][1000001] dp;
ulong N;

ulong solve(ulong i, ulong prev) {
  if (dp[i][prev] != INF) { return dp[i][prev]; }

  if (i == N) { return 1; }
  int ret;

  foreach (d; 3.iota) {
    d++;
    if (prev != d && i + d <= N) {
      ret += solve(i + d, d);
      ret %= M;
    }
  }

  return dp[i][prev] = ret;
}

void main() {
  foreach (i; 1000001.iota) {
    foreach (j; 4.iota) {
      dp[i][j] = INF;
    }
  }

  N = readln.chomp.to!ulong;
  writeln(solve(0, 0));
}
0