結果

問題 No.741 AscNumber(Easy)
ユーザー ikdikd
提出日時 2018-10-05 23:15:36
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 857 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 84,092 KB
実行使用メモリ 224,392 KB
最終ジャッジ日時 2023-09-03 21:10:06
合計ジャッジ時間 13,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 816 ms
214,072 KB
testcase_36 AC 360 ms
95,228 KB
testcase_37 AC 422 ms
111,600 KB
testcase_38 AC 416 ms
111,372 KB
testcase_39 AC 354 ms
93,904 KB
testcase_40 AC 475 ms
126,640 KB
testcase_41 AC 747 ms
195,272 KB
testcase_42 AC 398 ms
104,612 KB
testcase_43 AC 286 ms
78,044 KB
testcase_44 AC 587 ms
153,632 KB
testcase_45 AC 628 ms
166,160 KB
testcase_46 AC 769 ms
204,480 KB
testcase_47 AC 131 ms
36,832 KB
testcase_48 AC 770 ms
204,152 KB
testcase_49 AC 652 ms
170,268 KB
testcase_50 AC 88 ms
26,508 KB
testcase_51 AC 302 ms
80,512 KB
testcase_52 AC 857 ms
224,392 KB
testcase_53 AC 853 ms
224,348 KB
testcase_54 AC 841 ms
223,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  const int mod = 10 ^^ 9 + 7;
  auto memo = new int[][](n + 1, 10);
  afill(memo, -1);
  int f(int i, int prev) {
    if (i == n) {
      return 1;
    } else {
      if (memo[i][prev] >= 0) {
        return memo[i][prev];
      }
      int ret = 0;
      for (int digit = prev; digit <= 9; digit++) {
        (ret += f(i + 1, digit)) %= mod;
      }
      return memo[i][prev] = ret;
    }
  }

  writeln(f(0, 0));
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

void afill(Range, Type)(Range r, Type value) {
  static if (is(typeof(r) == Type[])) {
    foreach (ref elem; r)
      elem = value;
  } else {
    foreach (ref arr; r)
      afill(arr, value);
  }
}
0