結果

問題 No.741 AscNumber(Easy)
ユーザー ありあり
提出日時 2023-01-31 12:03:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 651 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 78,524 KB
実行使用メモリ 161,384 KB
最終ジャッジ日時 2023-09-13 06:00:30
合計ジャッジ時間 13,580 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
159,648 KB
testcase_01 AC 46 ms
159,568 KB
testcase_02 AC 44 ms
159,592 KB
testcase_03 AC 44 ms
159,808 KB
testcase_04 AC 44 ms
159,652 KB
testcase_05 AC 44 ms
159,664 KB
testcase_06 AC 44 ms
159,800 KB
testcase_07 AC 44 ms
159,572 KB
testcase_08 AC 44 ms
159,560 KB
testcase_09 AC 44 ms
159,612 KB
testcase_10 AC 44 ms
159,640 KB
testcase_11 AC 44 ms
159,800 KB
testcase_12 AC 43 ms
159,560 KB
testcase_13 AC 43 ms
159,652 KB
testcase_14 AC 43 ms
159,616 KB
testcase_15 AC 43 ms
159,596 KB
testcase_16 AC 43 ms
159,668 KB
testcase_17 AC 43 ms
159,664 KB
testcase_18 AC 43 ms
159,612 KB
testcase_19 AC 43 ms
159,616 KB
testcase_20 AC 44 ms
159,576 KB
testcase_21 AC 43 ms
159,568 KB
testcase_22 AC 44 ms
159,600 KB
testcase_23 AC 44 ms
159,568 KB
testcase_24 AC 45 ms
159,656 KB
testcase_25 AC 44 ms
159,592 KB
testcase_26 AC 45 ms
159,564 KB
testcase_27 AC 43 ms
159,668 KB
testcase_28 AC 43 ms
159,568 KB
testcase_29 AC 43 ms
159,592 KB
testcase_30 AC 43 ms
159,580 KB
testcase_31 AC 43 ms
159,796 KB
testcase_32 AC 42 ms
159,572 KB
testcase_33 AC 43 ms
159,580 KB
testcase_34 AC 43 ms
159,568 KB
testcase_35 AC 620 ms
160,276 KB
testcase_36 AC 298 ms
159,980 KB
testcase_37 AC 340 ms
159,884 KB
testcase_38 AC 337 ms
160,116 KB
testcase_39 AC 289 ms
159,912 KB
testcase_40 AC 378 ms
160,320 KB
testcase_41 AC 578 ms
160,328 KB
testcase_42 AC 323 ms
160,048 KB
testcase_43 AC 247 ms
159,888 KB
testcase_44 AC 455 ms
160,272 KB
testcase_45 AC 489 ms
160,348 KB
testcase_46 AC 592 ms
160,344 KB
testcase_47 AC 136 ms
159,792 KB
testcase_48 AC 593 ms
160,368 KB
testcase_49 AC 504 ms
160,264 KB
testcase_50 AC 105 ms
159,772 KB
testcase_51 AC 257 ms
159,960 KB
testcase_52 AC 651 ms
161,328 KB
testcase_53 AC 648 ms
161,384 KB
testcase_54 AC 647 ms
161,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;

const int mod = 1000000007;
struct mint {
  typedef long long ll;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[1000010][2][10] = {};
int main() {
  int n;
  cin >> n;
  string x;
  for (int i = 0; i < n; i++) x.push_back('9');
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    int d = x[i]-'0';
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 10; k++) {
        for (int l = 0; l <= (j ? 9 : d); l++) {
          if (l >= k) dp[i+1][j || (l < d)][l] += dp[i][j][k];
        }
      }
    }
  }
  mint ans = 0;
  for (int j = 0; j < 2; j++)
    for (int k = 0; k < 10; k++)
      ans += dp[n][j][k];
  
  cout << ans << endl;
  
}
0