結果

問題 No.41 貯金箱の溜息(EASY)
ユーザー omoiomoi
提出日時 2024-05-26 02:38:07
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 18,757 bytes
コンパイル時間 9,464 ms
コンパイル使用メモリ 285,628 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-12-20 20:07:40
合計ジャッジ時間 5,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
14,592 KB
testcase_01 AC 51 ms
14,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

namespace std {

    // 定数
    namespace ns_constant {

        //const long long MOD = 998244353;
        //const long long MOD = 1000000007;
        const long long MOD = 1000000009;

        const long long INF = 1LL << 60;
        const long long xorI = (1LL << 61) - 1;

        const long long mod = (1LL << 61) - 1;
        const long long MASK30 = (1LL << 30) - 1;
        const long long MASK31 = (1LL << 31) - 1;

        const long double PI = acos(-1);
        const long double eps = 1e-10;

        const long long dx[] = { 1, 0,-1, 0, 1,-1, 1,-1 };
        const long long dy[] = { 0, 1, 0,-1, 1,-1,-1, 1 };
        const pair<long long, long long> dxy[] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1} };

    }
    using namespace ns_constant;

    // 型定義
    namespace ns_type_define {

        template <typename T> using VT = vector<T>;

        typedef long long LI;
        typedef vector<LI> VI; typedef vector<VI> VVI; typedef vector<VVI> V3I; typedef vector<V3I> V4I;

        typedef long double LD;
        typedef vector<LD> VD; typedef vector<VD> VVD;

        typedef vector<bool> VB; typedef vector<VB> VVB;
        typedef vector<char> VC; typedef vector<VC> VVC;
        typedef vector<string> VS; typedef vector<VS> VVS;

        typedef pair<LI, LI> PII; typedef vector<PII> VPII; typedef vector<VPII> VVPII;
        typedef pair<LD, LD> PDD; typedef vector<PDD> VPDD; typedef vector<VPDD> VVPDD;
        typedef pair<string, LI> PSI; typedef vector<PSI> VPSI;

        typedef tuple<LI, LI, LI> TI; typedef vector<TI> VTI; typedef vector<VTI> VVTI;
        typedef tuple<LI, LI, LD> TD; typedef vector<TD> VTD; typedef vector<VTD> VVTD;

        typedef set<LI> SI; typedef set<PII> SPII; typedef multiset<LI> mSI;
        typedef vector<SI> VSI; typedef vector<VSI> VVSI;

        typedef map<LI, LI> MII; typedef map<PII, LI> MPIII; typedef multimap<LI, LI> mMII;
        typedef vector<MII> VMII; typedef vector<VMII> VVMII;
        typedef map<string, LI> MSI; typedef multimap<string, LI> mMSI; typedef vector<MSI> VMSI;

        typedef queue<LI> QI; typedef queue<PII> QPII;
        typedef priority_queue<PII, VPII, greater<PII>> PQPII;
        //優先順位付きqueue(昇順)

        template <typename T> using PQD = priority_queue<T>;
        template <typename T> using PQU = priority_queue<T, vector<T>, greater<T>>;
        template <typename T> using PQC = priority_queue<T, vector<T>, function<bool(T, T)>>;

    }
    using namespace ns_type_define;

    // マクロ
    namespace ns_macro {

        // ### 標準 ###
        namespace ns_macro_std {

#define mid(a, b, c)		    (a < b ? (a < c ? min(b, c) : a) : (b < c ? min(a, c) : b))

#define maxa(a, b)			    a = max(a, b);
#define mina(a, b)			    a = min(a, b);
#define mida(a, b, c)		    a = mid(a, b, c);

#define qpop(u, que)		    auto u = que.front(); que.pop();
#define qpop2(u, v, que)	    auto [u, v] = que.front(); que.pop();
#define qpop3(u, v, c, que)	    auto [u, v, c] = que.front(); que.pop();

#define pqpop(u, que)		    auto u = que.top(); que.pop();
#define pqpop2(u, v, que)	    auto [u, v] = que.top(); que.pop();
#define pqpop3(u, v, c, que)	auto [u, v, c] = que.top(); que.pop();

#define bits(x)				    (1LL << (x))
#define minf(x)				    ((x) != INF ? (x) : -1)

        }
        using namespace ns_macro_std;

        // ### ループ ###
        namespace ns_macro_loop {
            //
#define REP(i, j, k)			for (LI i = j; i < (LI)k; i++)
#define DREP(i, j, k)			for (LI i = k - 1; i >= (LI)j; i--)
#define rep(i, j)				for (int i = 0; i < (int)j; i++)
#define drep(i, j)				for (int i = (int)j - 1, i >= 0, i--)
#define repi(i, j)				for (int i = 1; i <= (int)j; i++)
#define drepi(i, j)				for (int i = (int)j; i > 0; i--)

#define vrep(a, v)				for (auto& a: v)
#define vrep2(a, b, v)			for (auto& [a, b]: v)
#define vrep3(a, b, c, v)		for (auto& [a, b, c]: v)
#define vrep4(a, b, c, d, v)	for (auto& [a, b, c, d]: v)

#define vcrep(a, v)				for (const auto& a: v)
#define vcrep2(a, b, v)			for (const auto& [a, b]: v)
#define vcrep3(a, b, c, v)		for (const auto& [a, b, c]: v)
#define vcrep4(a, b, c, d, v)	for (const auto& [a, b, c, d]: v)

// 集合 bit の部分集合を bit全探索
#define brep(subbit, bit)		for (LI subbit = bit; subbit; subbit = (subbit - 1) & bit)

// 要素数 R の部分集合を bit全探索
#define bcrep(bit, N, R)		for (LI bit = bits(R) - 1, x, y; bit < bits(N); x = bit & -bit, y = bit + x, bit = (((bit & ~y) / x) >> 1) | y)

        }
        using namespace ns_macro_loop;

        // ### 配列操作 ###
        namespace ns_macro_vector {

            void vsort(string& v) {
                sort(v.begin(), v.end());
            }
            template<typename T> void vsort(vector<T>& v) {
                sort(v.begin(), v.end());
            }
            void vsortr(string& v) {
                sort(v.begin(), v.end(), greater<char>());
            }
            template<typename T> void vsortr(vector<T>& v) {
                sort(v.begin(), v.end(), greater<T>());
            }

#define all(v)				        v.begin(), v.end()

#define vmax(v)				        (*max_element(all(v)))
#define vmin(v)				        (*min_element(all(v)))

#define miman(v, a)			        (lower_bound(all(v), a) - v.begin())
#define ika(v, a)			        (upper_bound(all(v), a) - v.begin())
#define ijo(v, a)			        (v.end() - lower_bound(all(v), a))
#define yorio(v, a)			        (v.end() - upper_bound(all(v), a))

#define iwa(W, A)			        VI W(1); vrep(a, A) W.push_back(W.back() + a);
#define dwa(W, A)			        VD W(1); vrep(a, A) W.push_back(W.back() + a);

#define vsorto(v, compare)          sort(all(v), compare);

#define vrev(v)				        reverse(all(v));

#define vcomp(v)				    v.erase(unique(all(v)), v.end());
#define vuni(v)			            vsort(v); vcomp(v);

        }
        using namespace ns_macro_vector;

        // ### 入力系 ###
        namespace ns_macro_input {

            namespace ns_macro_input_std {

#define scan(Type, a)						Type a; cin >> a;
#define scan2(Type, a, b)					scan(Type, a) scan(Type, b)
#define scan3(Type, a, b, c)				scan(Type, a) scan2(Type, b, c)
#define scan4(Type, a, b, c, d)				scan(Type, a) scan3(Type, b, c, d)

#define vscan(Type, A, N)					vector<Type> A((int)N);						                rep(mci, N) { cin >> A[mci]; }
#define vscan2(Type, A, B, N)				vector<Type> A((int)N), B((int)N);				            rep(mci, N) { cin >> A[mci] >> B[mci]; }
#define vscan3(Type, A, B, C, N)			vector<Type> A((int)N), B((int)N), C((int)N);			    rep(mci, N) { cin >> A[mci] >> B[mci] >> C[mci]; }
#define vscan4(Type, A, B, C, D, N)			vector<Type> A((int)N), B((int)N), C((int)N), D((int)N);	rep(mci, N) { cin >> A[mci] >> B[mci] >> C[mci] >> D[mci]; }

#define vvscan(Type, A, H, W)				vector A((int)H, vector<Type>((int)W));                     rep(mch, H) { rep(mcw, W) { cin >> A[(int)mch][(int)mcw]; } }


#define pscan(Type1, Type2, a)				pair<Type1, Type2> a; cin >> a.first >> a.second;
#define pscan2(Type1, Type2, a, b)			pscan(Type1, Type2, a) pscan(Type1, Type2, b);
#define pscan3(Type1, Type2, a, b, c)		pscan(Type1, Type2, a) pscan2(Type1, Type2, b, c);
#define pscan4(Type1, Type2, a, b, c, d)	pscan(Type1, Type2, a) pscan3(Type1, Type2, b, c, d);

#define vpscan(Type1, Type2, A, N)			vector<pair<Type1, Type2>> A((int)N);                      rep(mci, N) { cin >> A[mci].first >> A[mci].second; }


#define tscan(Type1, Type2, Type3, a)		Type1 mca; Type2 mcb; Type3 mcc;                            cin >> mca >> mcb >> mcc; tuple<Type1, Type2, Type3> a = { mca, mcb, mcc };

#define vtscan(A, N)						vector<tuple<Type1, Type2, Type3>> A((int)N);               rep(mci, N) { Type1 mca; Type2 mcb; Type3 mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; }

            }
            using namespace ns_macro_input_std;

            namespace ns_macro_input_longlong {

#define iscan(a)				scan(LI, a)
#define iscan2(a, b)			scan2(LI, a, b)
#define iscan3(a, b, c)			scan3(LI, a, b, c)
#define iscan4(a, b, c, d)		scan4(LI, a, b, c, d)

#define viscan(A, N)			vscan(LI, A, N)
#define viscan2(A, B, N)		vscan2(LI, A, B, N)
#define viscan3(A, B, C, N)		vscan3(LI, A, B, C, N)
#define viscan4(A, B, C, D, N)	vscan4(LI, A, B, C, D, N)

#define vviscan(A, H, W)		vvscan(LI, A, H, W)


#define piscan(a)				pscan(LI, LI, a)
#define piscan2(a, b)			pscan2(LI, LI, a, b)
#define piscan3(a, b, c)		pscan3(LI, LI, a, b, c)
#define piscan4(a, b, c, d)		pscan4(LI, LI, a, b, c, d)

#define vpiscan(A, N)			vpscan(LI, LI, A, N)


#define tiscan(a)				tscan(LI, LI, LI, a)

#define vtiscan(A, N)			VTI A((int)N); rep(mci, N) { LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; }

            }
            using namespace ns_macro_input_longlong;

            namespace ns_macro_input_longlong_decrease {

#define iscand(a)				iscan(a) a--;
#define iscand2(a, b)			iscand(a) iscand(b)
#define iscand3(a, b, c)		iscand(a) iscand2(b, c)
#define iscand4(a, b, c, d)		iscand(a) iscand3(b, c, d)

#define viscand(A, N)			viscan(A, N)			rep(mci, N) { A[mci]--; }
#define viscand2(A, B, N)		viscan2(A, B, N)		rep(mci, N) { A[mci]--; B[mci]--; }
#define viscand3(A, B, C, N)	viscan3(A, B, C, N)		rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; }
#define viscand4(A, B, C, D, N)	viscan4(A, B, C, D, N)	rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; D[mci]--; }

#define vviscand(A, H, W)		vviscan(A, H, W)		rep(mch, H) { rep(mcw, W) { A[mch][mcw]--; } }


#define piscand(a)				piscan(a); a.first--; a.second--;
#define piscand2(a, b)			piscand(a) piscand(b)
#define piscand3(a, b, c)		piscand(a) piscand2(b, c)
#define piscand4(a, b, c, d)	piscand(a) piscand3(b, c, d)

#define vpiscand(A, N)			vpiscan(A, N); rep(mci, N) { A[mci].first--; A[mci].second--; }


#define tiscand(a)				LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; TI a = { mca, mcb, mcc }; 

#define vtiscand(A, N)			VTI A(N); rep(mci, N) { LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca - 1, mcb - 1, mcc }; }

            }
            using namespace ns_macro_input_longlong_decrease;

            namespace ns_macro_input_longdouble {

#define dscan(a)				scan(LD, a)
#define dscan2(a, b)			scan2(LD, a, b)
#define dscan3(a, b, c)			scan3(LD, a, b, c)
#define dscan4(a, b, c, d)		scan4(LD, a, b, c, d)

#define vdscan(A, N)			vscan(LD, A, N)
#define vdscan2(A, B, N)		vscan2(LD, A, B, N)
#define vdscan3(A, B, C, N)		vscan3(LD, A, B, C, N)
#define vdscan4(A, B, C, D, N)	vscan4(LD, A, B, C, D, N)

#define vvdscan(A, H, W)		vvscan(LD, A, H, W)


#define pdscan(a)				pscan(LD, LD, a)
#define pdscan2(a, b)			pscan2(LD, LD, a, b)
#define pdscan3(a, b, c)		pscan3(LD, LD, a, b, c)
#define pdscan4(a, b, c, d)		pscan4(LD, LD, a, b, c, d)

#define vpdscan(A, N)			vpscan(LD, LD, A, N)


#define tdscan(a)				tscan(LI, LI, LD, a)

#define vtdscan(A, N)			VTD A(N); rep(mci, N) { LI mca, mcb; LD mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; }


#define tdscand(a)				tscand(LI, LI, LD, a)

#define vtdscand(A, N)			VTD A(N); rep(mci, N) { LI mca, mcb; LD mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca - 1, mcb - 1, mcc }; }

            }
            using namespace ns_macro_input_longdouble;

            namespace ns_macro_input_string {

#define sscan(a)				scan(string, a)
#define sscan2(a, b)			scan2(string, a, b)
#define sscan3(a, b, c)			scan3(string, a, b, c)
#define sscan4(a, b, c, d)		scan4(string, a, b, c, d)

#define vsscan(S, N)			vscan(string, S, N)

            }
            using namespace ns_macro_input_string;

        }
        using namespace ns_macro_input;

        // ### 出力系 ###
        namespace ns_macro_output {

            namespace ns_macro_output_std {

#define el					cout << endl;

#define show(a)				cout << (a) << endl;
#define show2(a, b)			cout << (a) << " " << (b) << endl;
#define show3(a, b, c)		cout << (a) << " " << (b) << " " << (c) << endl;
#define show4(a, b, c, d)	cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl;

#define shown(a)			cout << (a) << " ";
#define shown2(a, b)		cout << (a) << " " << (b) << " ";
#define shown3(a, b, c)		cout << (a) << " " << (b) << " " << (c) << " ";
#define shown4(a, b, c, d)	cout << (a) << " " << (b) << " " << (c) << " " << (d) << " ";

#define vshow(A)			vcrep(a, A) { show(a) }
#define vshown(A)			vcrep(a, A) { shown(a) } el
#define vvshow(A)			vcrep(a, A) { vshown(a) }


#define pshow(a)			show2((a).first, (a).second)
#define pshown(a)			shown2((a).first, (a).second)
#define pshow2(a, b)		pshown(a) pshow(b)

#define vpshow(A)			vcrep(a, A) { pshow(a) }


#define tshow(a)			show3(get<0>(a), get<1>(a), get<2>(a))
#define tshown(a)			shown3(get<0>(a), get<1>(a), get<2>(a))

#define vtshow(A)			vcrep(a, A) { tshow(a) }


#define showif(f, a, b)		if (f) { show(a) } else { show(b) }
#define shownif(f, a, b)	if (f) { shown(a) } else { shown(b) }

#define yes(f)				showif(f, "Yes", "No")

            }
            using namespace ns_macro_output_std;

            namespace ns_macro_output_by_type {

#define ishow(a)			show(minf(a))
#define ishown(a)			shown(minf(a))

#define vishow(A)			vcrep(a, A) { ishow(a) }
#define vishown(A)			vcrep(a, A) { ishown(a) } el
#define vvishow(A)			vcrep(a, A) { vishown(a) }


#define dnshow(x, n)		cout << fixed << setprecision(n) << (x) << endl;
#define dnshown(x, n)		cout << fixed << setprecision(n) << (x) << " ";

#define vdnshow(A, n)		vcrep(a, A) { dshow(a, n) }
#define vdnshown(A, n)		vcrep(a, A) { dshown(a, n) } el
#define vvdnshow(A, n)		vcrep(a, A) { vdshown(a, n) }


#define dshow(x)			cout << fixed << setprecision(10) << (x) << endl;
#define dshown(x)   		cout << fixed << setprecision(10) << (x) << " ";

#define vdshow(A)   		vcrep(a, A) { dshow(a) }
#define vdshown(A)	    	vcrep(a, A) { dshown(a) } el
#define vvdshow(A)  		vcrep(a, A) { vdshown(a) }


#define bshow(a, n)			show(bitset<n>(a))
#define bshown(a, n)		shown(bitset<n>(a))

#define vbshow(A, n)		vcrep(a, A) { show(bitset<n>(a)) }
#define vbshown(A, n)		vcrep(a, A) { shown(bitset<n>(a)) } el
#define vvbshow(A, n)		vcrep(a, A) { vbshow(a, n) }

            }
            using namespace ns_macro_output_by_type;

            namespace ns_macro_output_debug {

#define debughead			shown(">>")

#define debugm(a)			shown3(#a, "=", a)
#define debugn(a)			debugm(a) shown(",")

#define debug(a)			debughead debugm(a) el
#define debug2(a, b)		debughead debugn(a) debugm(b) el
#define debug3(a, b, c)		debughead debugn(a) debugn(b) debugm(c) el
#define debug4(a, b, c, d)	debughead debugn(a) debugn(b) debugn(c) debugm(d) el

            }
            using namespace ns_macro_output_debug;

        }
        using namespace ns_macro_output;

    }
    using namespace ns_macro;

}

template<long long modification> class mod_long_long {
private:
    long long val;

public:
    constexpr mod_long_long(long long v = 0) noexcept : val(v% modification) {
        if (val < 0) val += modification;
    }

    constexpr long long get_mod() { return modification; }
    constexpr long long get_li() { return val; }
    constexpr mod_long_long operator - () const noexcept { return val ? modification - val : 0; }
    constexpr mod_long_long operator + (const mod_long_long& r) const noexcept { return mod_long_long(*this) += r; }
    constexpr mod_long_long operator - (const mod_long_long& r) const noexcept { return mod_long_long(*this) -= r; }
    constexpr mod_long_long operator * (const mod_long_long& r) const noexcept { return mod_long_long(*this) *= r; }
    constexpr mod_long_long operator / (const mod_long_long& r) const noexcept { return mod_long_long(*this) /= r; }
    constexpr mod_long_long& operator += (const mod_long_long& r) noexcept {
        val += r.val;
        if (val >= modification) val -= modification;
        return *this;
    }
    constexpr mod_long_long& operator -= (const mod_long_long& r) noexcept {
        val -= r.val;
        if (val < 0) val += modification;
        return *this;
    }
    constexpr mod_long_long& operator *= (const mod_long_long& r) noexcept {
        val = val * r.val % modification;
        return *this;
    }
    constexpr mod_long_long& operator /= (const mod_long_long& r) noexcept {
        long long a = r.val, b = modification, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % modification;
        if (val < 0) val += modification;
        return *this;
    }
    constexpr bool operator == (const mod_long_long& r) const noexcept { return this->val == r.val; }
    constexpr bool operator != (const mod_long_long& r) const noexcept { return this->val != r.val; }
    constexpr mod_long_long operator ++ () {
        val += 1;
        if (val >= modification) val -= modification;
        return *this;
    }
    constexpr mod_long_long operator -- () {
        val -= 1;
        if (val < 0) val += modification;
        return *this;
    }
    constexpr mod_long_long operator ++ (int) {
        mod_long_long temp = *this;
        ++(*this);
        return temp;
    }
    constexpr mod_long_long operator -- (int) {
        mod_long_long temp = *this;
        --(*this);
        return temp;
    }
    friend constexpr ostream& operator << (ostream& os, const mod_long_long<modification>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream& os, mod_long_long<modification>& x) noexcept {
        return os >> x.val;
    }
    friend constexpr mod_long_long<modification> modpow(const mod_long_long<modification>& a, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return (mod_long_long<modification>)1 / modpow(a, -n);
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using MI = mod_long_long<MOD>;
using VMI = VT<MI>;

// べき乗
LI ipow(const LI& a, const LI& ex, const LI mod = 0) {
    if (ex == 0) return 1;
    LI res = ipow(a, ex / 2, mod);
    res *= res;
    if (mod) res %= mod;
    if (ex & 1) res *= a;
    if (mod) res %= mod;
    return res;
}

int main() {
    const LI C = 111111;
    const LI N = ipow(10, 10) / C;
    VT<VMI> dp(N + 1, VMI(10));
    rep(i, N + 1) dp[i][0] = 1;
    rep(i, N) rep(j, 10) {
        if (dp[i][j] == 0) continue;
        REP(k, j, 10) {
            if (k == 0) continue;
            if (i + k > N) break;
            dp[i + k][k] += dp[i][j];
        }
    }
    VMI ans(N + 1);
    rep(i, N + 1) rep(j, 10) ans[i] += dp[i][j];
    iscan(T);
    while (T--) {
        iscan(M);
        M /= 111111;
        show(ans[M]);
    }
}
0