結果

問題 No.741 AscNumber(Easy)
ユーザー Feishi LiFeishi Li
提出日時 2024-01-19 11:57:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 2,806 bytes
コンパイル時間 4,097 ms
コンパイル使用メモリ 267,044 KB
実行使用メモリ 215,244 KB
最終ジャッジ日時 2024-01-19 11:57:20
合計ジャッジ時間 14,034 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 551 ms
205,304 KB
testcase_36 AC 242 ms
91,344 KB
testcase_37 AC 285 ms
106,916 KB
testcase_38 AC 279 ms
105,456 KB
testcase_39 AC 238 ms
89,636 KB
testcase_40 AC 323 ms
120,600 KB
testcase_41 AC 497 ms
187,676 KB
testcase_42 AC 267 ms
100,932 KB
testcase_43 AC 194 ms
73,876 KB
testcase_44 AC 397 ms
147,636 KB
testcase_45 AC 425 ms
158,952 KB
testcase_46 AC 525 ms
195,536 KB
testcase_47 AC 90 ms
35,832 KB
testcase_48 AC 522 ms
195,556 KB
testcase_49 AC 436 ms
163,932 KB
testcase_50 AC 63 ms
25,088 KB
testcase_51 AC 206 ms
77,392 KB
testcase_52 AC 569 ms
215,244 KB
testcase_53 AC 577 ms
215,244 KB
testcase_54 AC 597 ms
213,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <bits/extc++.h>
using i64 = long long;
template <typename T, T MOD = 1000000007>
struct Mint
{
    inline static constexpr T mod = MOD;
    T v;
    Mint() : v(0) {}
    Mint(signed v) : v(v) {}
    Mint(long long t)
    {
        v = t % MOD;
        if (v < 0)
            v += MOD;
    }

    Mint pow(long long k)
    {
        Mint res(1), tmp(v);
        while (k)
        {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static Mint add_identity() { return Mint(0); }
    static Mint mul_identity() { return Mint(1); }

    Mint inv() { return pow(MOD - 2); }

    Mint &operator+=(Mint a)
    {
        v += a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator-=(Mint a)
    {
        v += MOD - a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator*=(Mint a)
    {
        v = 1LL * v * a.v % MOD;
        return *this;
    }
    Mint &operator/=(Mint a) { return (*this) *= a.inv(); }

    Mint operator+(Mint a) const { return Mint(v) += a; }
    Mint operator-(Mint a) const { return Mint(v) -= a; }
    Mint operator*(Mint a) const { return Mint(v) *= a; }
    Mint operator/(Mint a) const { return Mint(v) /= a; }

    Mint operator+() const { return *this; }
    Mint operator-() const { return v ? Mint(MOD - v) : Mint(v); }

    bool operator==(const Mint a) const { return v == a.v; }
    bool operator!=(const Mint a) const { return v != a.v; }

    static Mint comb(long long n, int k)
    {
        Mint num(1), dom(1);
        for (int i = 0; i < k; i++)
        {
            num *= Mint(n - i);
            dom *= Mint(i + 1);
        }
        return num / dom;
    }
};
template <typename T, T MOD>
std::ostream &operator<<(std::ostream &os, Mint<T, MOD> m)
{
    os << m.v;
    return os;
}
using Z = Mint<i64>;
void solve()
{
    int n;
    std::cin >> n;
    std::string s = "1" + std::string(n, '0');
    n = n + 1;
    const i64 NIL = -1;
    std::vector dp(n, std::vector(10, NIL));
    auto dfs = [&](auto self, int i, int cur, bool is_limit, bool is_asc) -> Z
    {
        if (i == n)
        {
            return is_asc;
        }
        auto &ndp = dp[i][cur];
        if (ndp != NIL)
        {
            return ndp;
        }
        Z ans = 0;
        int up = is_limit ? s[i] - '0' : 9;
        for (int d = 0; d <= up; d++)
        {
            if (d >= cur)
            {
                ans += self(self, i + 1, d, is_limit and d == up, true);
            }
        }
        return ndp = ans.v;
    };
    std::cout << dfs(dfs, 0, 0, true, true) << '\n';
}
int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
    return 0;
}
0