結果

問題 No.741 AscNumber(Easy)
ユーザー ikd
提出日時 2018-10-05 23:15:36
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 806 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 99,236 KB
実行使用メモリ 222,592 KB
最終ジャッジ日時 2024-06-13 01:50:49
合計ジャッジ時間 12,860 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

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