結果

問題 No.741 AscNumber(Easy)
ユーザー naotaka nakanenaotaka nakane
提出日時 2023-02-20 23:41:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 4,163 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 171,236 KB
実行使用メモリ 276,596 KB
最終ジャッジ日時 2023-09-28 18:49:27
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 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,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 439 ms
263,724 KB
testcase_36 AC 194 ms
116,544 KB
testcase_37 AC 227 ms
136,804 KB
testcase_38 AC 222 ms
134,668 KB
testcase_39 AC 190 ms
114,236 KB
testcase_40 AC 253 ms
154,564 KB
testcase_41 AC 392 ms
240,812 KB
testcase_42 AC 212 ms
129,020 KB
testcase_43 AC 156 ms
93,980 KB
testcase_44 AC 310 ms
189,272 KB
testcase_45 AC 338 ms
203,880 KB
testcase_46 AC 413 ms
250,900 KB
testcase_47 AC 74 ms
45,012 KB
testcase_48 AC 417 ms
251,128 KB
testcase_49 AC 342 ms
210,056 KB
testcase_50 AC 51 ms
31,036 KB
testcase_51 AC 165 ms
98,728 KB
testcase_52 AC 452 ms
276,540 KB
testcase_53 AC 452 ms
276,596 KB
testcase_54 AC 447 ms
273,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;

const int IntINF = 1 << 30;
const ll LLINF = 1LL << 60;

#define REP(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)

#define what_is(x) cerr << #x << " is " << x << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) { os << v[i] << (i < (ll)v.size() - 1 ? " " : ""); }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  rep(i, v.size()) {
    rep(j, v[i].size()) {
      os << v[i][j] << (j < (ll)v[i].size() - 1 ? " " : "");
    }
    os << endl;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
  for (const auto &p : v) {
    os << p.first << ": " << p.second << endl;
  }
  return os;
}

inline void io_setup(int precision = 15) {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(precision);
  cerr << fixed << setprecision(precision);
}

constexpr int MOD1 = 1000000007;
constexpr int MOD2 = 998244353;
constexpr int MOD3 = 1000000009;

template <int MOD> struct Mint {
  long long val;
  constexpr Mint(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      v += MOD;
  }
  constexpr int get_mod() { return MOD; }
  constexpr Mint operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Mint operator+(const Mint &r) const noexcept {
    return Mint(*this) += r;
  }
  constexpr Mint operator-(const Mint &r) const noexcept {
    return Mint(*this) -= r;
  }
  constexpr Mint operator*(const Mint &r) const noexcept {
    return Mint(*this) *= r;
  }
  constexpr Mint &operator+=(const Mint &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Mint &operator-=(const Mint &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Mint &operator*=(const Mint &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr bool operator==(const Mint &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Mint &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr istream &operator>>(istream &is, Mint<MOD> &x) noexcept {
    is >> x.val;
    x.val %= MOD;
    if (x.val < 0)
      x.val += MOD;
    return is;
  }
  friend constexpr ostream &operator<<(ostream &os,
                                       const Mint<MOD> &x) noexcept {
    return os << x.val;
  }
};

template <typename T> struct ModBinomialCoefficient {
private:
  vector<T> fact, inv, fact_inv;

public:
  constexpr ModBinomialCoefficient(int n) noexcept
      : fact(n, 1), inv(n, 1), fact_inv(n, 1) {
    int MOD = fact[0].get_mod();
    for (int i = 2; i < n; ++i) {
      fact[i] = fact[i - 1] * i;
      inv[i] = -inv[MOD % i] * (MOD / i);
      fact_inv[i] = fact_inv[i - 1] * inv[i];
    }
  }

  constexpr T combination(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact[n] * fact_inv[k] * fact_inv[n - k];
  }
};

using Mint1 = Mint<MOD1>;
using Mint2 = Mint<MOD2>;
using Mint3 = Mint<MOD3>;
using vMint1 = vector<Mint1>;
using vvMint1 = vector<vMint1>;
using vvvMint1 = vector<vvMint1>;

int main() {
  io_setup();

  int N;
  cin >> N;

  vvvMint1 dp(N + 1, vvMint1(2, vMint1(10, 0)));
  dp[0][0][9] = 1;

  rep(i, N) {
    int D = 9;
    rep(smaller, 2) {
      rep(j, 10) {
        if (smaller == 0) {
          rep(d, min(D + 1, (int)j + 1)) {
            dp[i + 1][d == D ? 0 : 1][d] += dp[i][smaller][j];
          }
        } else {
          rep(d, j + 1) { dp[i + 1][smaller][d] += dp[i][smaller][j]; }
        }
      }
    }
  }
  Mint1 ans = 0;
  rep(i, 10) { ans += dp[N][0][i] + dp[N][1][i]; }
  cout << ans << endl;

  return 0;
}
0