結果

問題 No.741 AscNumber(Easy)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-14 11:53:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 67,648 KB
実行使用メモリ 153,628 KB
最終ジャッジ日時 2023-09-09 10:53:41
合計ジャッジ時間 7,437 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 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,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 333 ms
148,164 KB
testcase_36 AC 145 ms
66,072 KB
testcase_37 AC 170 ms
77,528 KB
testcase_38 AC 168 ms
77,124 KB
testcase_39 AC 142 ms
65,380 KB
testcase_40 AC 198 ms
88,240 KB
testcase_41 AC 305 ms
135,960 KB
testcase_42 AC 166 ms
73,332 KB
testcase_43 AC 121 ms
53,860 KB
testcase_44 AC 245 ms
105,836 KB
testcase_45 AC 255 ms
115,704 KB
testcase_46 AC 315 ms
140,556 KB
testcase_47 AC 55 ms
26,752 KB
testcase_48 AC 316 ms
140,552 KB
testcase_49 AC 262 ms
117,360 KB
testcase_50 AC 38 ms
18,900 KB
testcase_51 AC 122 ms
57,172 KB
testcase_52 AC 349 ms
153,628 KB
testcase_53 AC 351 ms
153,628 KB
testcase_54 AC 348 ms
152,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
constexpr int MOD = 1e9+7;
using mint = MInt<MOD>;

constexpr int MAX_N = 1e6;
bool visited[MAX_N+1][10];
mint dp[MAX_N+1][10];

mint dfs(int n, int t) {
  // 10^n未満で、直前の桁の数がtであるときのAscNumberの個数
  if (n == 1)
    return 10-t;
  if (visited[n][t])
    return dp[n][t];
  mint ans = 0;
  rep(i, 10-t) {
    ans += dfs(n-1, t+i);
  }
  visited[n][t] = true;
  return dp[n][t] = ans;
}

int main() {
  int N; cin >> N;

  cout << dfs(N, 0) << endl;

  return 0;
}
0