結果

問題 No.533 Mysterious Stairs
ユーザー d2verbd2verb
提出日時 2018-10-17 02:25:58
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 173 ms / 5,000 ms
コード長 819 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 91,668 KB
実行使用メモリ 52,420 KB
最終ジャッジ日時 2023-09-03 21:12:44
合計ジャッジ時間 6,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
52,300 KB
testcase_01 AC 145 ms
51,008 KB
testcase_02 AC 144 ms
51,944 KB
testcase_03 AC 145 ms
50,868 KB
testcase_04 AC 145 ms
50,724 KB
testcase_05 AC 144 ms
50,592 KB
testcase_06 AC 144 ms
50,544 KB
testcase_07 AC 147 ms
52,420 KB
testcase_08 AC 145 ms
50,644 KB
testcase_09 AC 145 ms
50,612 KB
testcase_10 AC 144 ms
50,868 KB
testcase_11 AC 145 ms
51,680 KB
testcase_12 AC 144 ms
50,700 KB
testcase_13 AC 145 ms
50,948 KB
testcase_14 AC 142 ms
51,748 KB
testcase_15 AC 143 ms
50,760 KB
testcase_16 AC 143 ms
51,436 KB
testcase_17 AC 142 ms
50,920 KB
testcase_18 AC 145 ms
51,060 KB
testcase_19 AC 146 ms
52,080 KB
testcase_20 AC 148 ms
51,228 KB
testcase_21 AC 149 ms
52,220 KB
testcase_22 AC 153 ms
51,480 KB
testcase_23 AC 172 ms
51,356 KB
testcase_24 AC 173 ms
50,520 KB
testcase_25 AC 147 ms
50,944 KB
testcase_26 AC 169 ms
50,404 KB
testcase_27 AC 152 ms
50,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.format;
import std.array;
import std.math;
import std.string;
import std.container;

void main() {
  int N; readlnTo(N);
  auto dp = new int[][](1000001, 4);
  const int mod = 1000000007;

  dp[0][0] = 1;

  int val;
  foreach(i; 0..N) {
    foreach(j; 1..4) {
      if (i + j > N)
        continue;
      val = dp[i+j][j];
      foreach(k; 0..4) {
        if (j == k)
          continue;
        val = (val + dp[i][k]) % mod;
      }
      dp[i+j][j] = val;
    }
  }

  int ans = 0;
  foreach(i; 1..4)
    ans = (ans + dp[N][i]) % mod;

  ans.writeln;
}

// helpers
void readlnTo(T...)(ref T t) {
  auto s = readln.split;
  assert(s.length == t.length);
  foreach(ref ti; t) {
    ti = s[0].to!(typeof(ti));
    s = s[1..$];
  }
}
0