結果

問題 No.741 AscNumber(Easy)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-10-06 11:45:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 664 ms / 2,000 ms
コード長 1,477 bytes
コンパイル時間 985 ms
コンパイル使用メモリ 91,204 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 17:48:15
合計ジャッジ時間 10,841 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 638 ms
6,940 KB
testcase_36 AC 273 ms
6,944 KB
testcase_37 AC 332 ms
6,940 KB
testcase_38 AC 323 ms
6,940 KB
testcase_39 AC 277 ms
6,944 KB
testcase_40 AC 367 ms
6,940 KB
testcase_41 AC 581 ms
6,940 KB
testcase_42 AC 311 ms
6,944 KB
testcase_43 AC 226 ms
6,944 KB
testcase_44 AC 464 ms
6,940 KB
testcase_45 AC 501 ms
6,940 KB
testcase_46 AC 601 ms
6,940 KB
testcase_47 AC 106 ms
6,940 KB
testcase_48 AC 602 ms
6,940 KB
testcase_49 AC 499 ms
6,940 KB
testcase_50 AC 69 ms
6,944 KB
testcase_51 AC 235 ms
6,940 KB
testcase_52 AC 664 ms
6,944 KB
testcase_53 AC 659 ms
6,940 KB
testcase_54 AC 662 ms
6,944 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<vector<i64>>> dp(2, vector<vector<i64>>(2, vector<i64>(10, 0)));
  dp[0][0][0] = 1;
  for(int i=0; i<n; ++i) {
    vector<vector<vector<i64>>> ndp(2, vector<vector<i64>>(2, vector<i64>(10, 0)));
    for(int less=0; less<2; ++less) {
      for(int nuke0=0; nuke0<2; ++nuke0) {
        for(int before=0; before<10; ++before) {
          if(!dp[less][nuke0][before]) { continue; }
          int start = nuke0 ? before : 0;
          for(int d=start; d<=(less ? 9 : s[i]-'0'); ++d) {
            int nless  = less || d < s[i] - '0',
                n_nuke0 = nuke0 || d > 0,
                nbefore = d;
            ndp[nless][n_nuke0][nbefore] += dp[less][nuke0][before];
            ndp[nless][n_nuke0][nbefore] %= mod;
          }
        }
      }
    }
    dp = ndp;
  }
  i64 res = 0;
  for(int less=0; less<2; ++less) {
    for(int nuke0=0; nuke0<2; ++nuke0) {
      for(int before=0; before<10; ++before) {
        res += dp[less][nuke0][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