結果

問題 No.741 AscNumber(Easy)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-10-06 11:55:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 84,384 KB
実行使用メモリ 5,424 KB
最終ジャッジ日時 2024-04-20 17:48:50
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 217 ms
5,376 KB
testcase_36 AC 94 ms
5,376 KB
testcase_37 AC 113 ms
5,376 KB
testcase_38 AC 112 ms
5,376 KB
testcase_39 AC 98 ms
5,376 KB
testcase_40 AC 127 ms
5,376 KB
testcase_41 AC 197 ms
5,376 KB
testcase_42 AC 105 ms
5,376 KB
testcase_43 AC 79 ms
5,376 KB
testcase_44 AC 158 ms
5,376 KB
testcase_45 AC 165 ms
5,376 KB
testcase_46 AC 205 ms
5,376 KB
testcase_47 AC 38 ms
5,376 KB
testcase_48 AC 208 ms
5,388 KB
testcase_49 AC 177 ms
5,376 KB
testcase_50 AC 26 ms
5,376 KB
testcase_51 AC 82 ms
5,376 KB
testcase_52 AC 221 ms
5,416 KB
testcase_53 AC 224 ms
5,376 KB
testcase_54 AC 225 ms
5,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;

constexpr int mod = static_cast<int>(powl(10, 9)) + 7;

i64 f(string s) {
  int n = static_cast<int>(s.size());
  // dp[未満フラグ][前の数字] := パターン数
  vector<vector<i64>> dp(2, vector<i64>(10, 0));
  dp[0][0] = 1;
  for(int i=0; i<n; ++i) {
    vector<vector<i64>> ndp(2, vector<i64>(10, 0));
    for(int less=0; less<2; ++less) {
      for(int before=0; before<10; ++before) {
        if(!dp[less][before]) { continue; }
        for(int d=before; d<=(less ? 9 : s[i]-'0'); ++d) {
          int nless  = less || d < s[i] - '0',
              nbefore = d;
          ndp[nless][nbefore] += dp[less][before];
          ndp[nless][nbefore] %= mod;
        }
      }
    }
    dp = ndp;
  }
  i64 res = 0;
  for(int less=0; less<2; ++less) {
    for(int before=0; before<10; ++before) {
      res += dp[less][before];
      res %= mod;
    }
  }
  return res;
}

int main(void) {
  int n; scanf("%d", &n);
  string s = "";
  for(int i=0; i<n; ++i) {
    s += '9';
  }
  i64 res = f(s);
  printf("%ld\n", res);
  return 0;
}
0