結果

問題 No.41 貯金箱の溜息(EASY)
ユーザー PachicobuePachicobue
提出日時 2017-07-03 17:26:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,086 ms / 5,000 ms
コード長 1,441 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 164,136 KB
実行使用メモリ 17,500 KB
最終ジャッジ日時 2024-04-15 14:39:18
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = 1e9 + 9;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr ll MAX = (10000000000 / 111111);
ll dp[10][MAX + 1];  // i番目まででy円
ll sum[10][MAX + 1];

int main()
{
    dp[0][0] = 1;
    for (ll y = 0; y <= MAX; y++) {
        sum[0][y] = 1;
    }
    for (ll i = 1; i <= 9; i++) {
        for (ll y = 0; y <= MAX; y++) {
            dp[i][y] = sum[i - 1][y];
            if (y >= i + 1) {
                sum[i][y] = (sum[i][y - (i + 1)] + dp[i][y]) % MOD;
            } else {
                sum[i][y] = dp[i][y];
            }
        }
    }

    ll T;
    cin >> T;
    for (ll t = 0; t < T; t++) {
        ll M;
        cin >> M;
        const ll m = M / 111111;
        ll sum = 0;
        for (ll y = 0; y <= m; y++) {
            sum = (sum + dp[9][y]) % MOD;
        }
        cout << sum << endl;
    }
    return 0;
}
0