結果

問題 No.41 貯金箱の溜息(EASY)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2017-10-31 18:13:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 165,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 13:31:12
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {
    typedef long long ll;
    ll T;
    ll M;
    void solve();
    void show();
    void doit() {
        solve();
        cin >> T;
        for (auto i = 0; i < T; i++) {
            cin >> M;
            show();
        }
    }

    /** output whole vector. ex) vector<int>{1, 2, 3} -> '1 2 3'. */
    template<typename T>
    ostream& operator<<(ostream& os, const vector<T>& xs) {
       if (xs.empty()) return os;
       os << xs[0];
       for (auto i = 1; i < xs.size(); i++) os << ' ' << xs[i];
       return os;
    }

    ll g[100005];
    void solve() {
        ll M = 10000000000L;
        const ll unit = 111*1000 + 111;
        const ll MOD = ll(1e9 + 9);
        auto m = M / unit;
        for (auto x = 0; x < 100005; x++) g[x] = 1;
        for (auto k = 1; k <= 9; k++) {
            for (auto x = 0; x <= m; x++) {
                if (x - k >= 0) {
                    g[x] += g[x - k];
                    if (g[x] >= MOD) g[x] -= MOD;
                }
                //g[x][k] = 0;
                //for (auto t = 0; t * k <= x; t++) {
                //    g[x][k] = (g[x][k] + g[x - t * k][k - 1]) % MOD;
                //}
            }
        }
    }

    void show() {
        const ll unit = 111*1000 + 111;
        auto m = M / unit;
        ll ans = g[m];
        cout << ans << endl;
    }
}

int main() {
    doit();
    return 0;
}

0