結果

問題 No.741 AscNumber(Easy)
ユーザー sarashinsarashin
提出日時 2019-09-19 22:10:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 2,584 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 167,136 KB
実行使用メモリ 183,248 KB
最終ジャッジ日時 2023-09-27 23:17:10
合計ジャッジ時間 11,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
182,264 KB
testcase_01 AC 85 ms
182,276 KB
testcase_02 AC 83 ms
182,424 KB
testcase_03 AC 92 ms
182,372 KB
testcase_04 AC 82 ms
182,284 KB
testcase_05 AC 84 ms
182,280 KB
testcase_06 AC 85 ms
182,476 KB
testcase_07 AC 82 ms
182,260 KB
testcase_08 AC 82 ms
182,268 KB
testcase_09 AC 82 ms
182,276 KB
testcase_10 AC 81 ms
182,244 KB
testcase_11 AC 83 ms
182,216 KB
testcase_12 AC 83 ms
182,284 KB
testcase_13 AC 82 ms
182,316 KB
testcase_14 AC 84 ms
182,252 KB
testcase_15 AC 85 ms
182,212 KB
testcase_16 AC 84 ms
182,268 KB
testcase_17 AC 82 ms
182,264 KB
testcase_18 AC 81 ms
182,348 KB
testcase_19 AC 82 ms
182,432 KB
testcase_20 AC 83 ms
182,480 KB
testcase_21 AC 83 ms
182,252 KB
testcase_22 AC 83 ms
182,376 KB
testcase_23 AC 83 ms
182,432 KB
testcase_24 AC 84 ms
182,252 KB
testcase_25 AC 83 ms
182,348 KB
testcase_26 AC 81 ms
182,284 KB
testcase_27 AC 82 ms
182,488 KB
testcase_28 AC 84 ms
182,272 KB
testcase_29 AC 85 ms
182,468 KB
testcase_30 AC 84 ms
182,268 KB
testcase_31 AC 83 ms
182,284 KB
testcase_32 AC 82 ms
182,276 KB
testcase_33 AC 82 ms
182,412 KB
testcase_34 AC 83 ms
182,280 KB
testcase_35 AC 362 ms
183,008 KB
testcase_36 AC 209 ms
182,740 KB
testcase_37 AC 227 ms
182,484 KB
testcase_38 AC 228 ms
182,508 KB
testcase_39 AC 205 ms
182,536 KB
testcase_40 AC 255 ms
182,556 KB
testcase_41 AC 340 ms
183,248 KB
testcase_42 AC 221 ms
182,540 KB
testcase_43 AC 182 ms
182,596 KB
testcase_44 AC 288 ms
182,844 KB
testcase_45 AC 303 ms
182,820 KB
testcase_46 AC 355 ms
183,040 KB
testcase_47 AC 128 ms
182,604 KB
testcase_48 AC 349 ms
183,104 KB
testcase_49 AC 309 ms
182,820 KB
testcase_50 AC 113 ms
182,596 KB
testcase_51 AC 188 ms
182,484 KB
testcase_52 AC 381 ms
182,996 KB
testcase_53 AC 377 ms
182,992 KB
testcase_54 AC 378 ms
182,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while(exp) {
            if(exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
using mint = modint<MOD>;

constexpr int M = 1145141;

mint dp[M][2][10];

int main(int argc, char const *argv[]) {
    int a; cin>>a;
    string s = "1";
    rep(i,a) s.push_back('0');
    int n = s.length();
    rep(i,M) rep(j,2) rep(k,10) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    rep(i,n) {
        int D = (int)(s[i]-'0');
        rep(j,2) {
            for (int x = 0; x <= (j?9:D); ++x) {
                rep(k,10) {
                    if (x < k) continue;
                    dp[i+1][j||(x<D)][x] += dp[i][j][k];
                }
            }
        }
    }

    mint ans = 0;
    rep(j,2) {
        rep(k,10) {
            ans += dp[n][j][k];
        }
    }

    cout << ans.a << endl;

    return 0;
}
0