結果

問題 No.250 atetubouのzetubou
ユーザー __t2kasa____t2kasa__
提出日時 2018-09-01 08:33:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,721 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 165,644 KB
実行使用メモリ 38,700 KB
最終ジャッジ日時 2023-10-12 20:39:16
合計ジャッジ時間 3,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
38,472 KB
testcase_01 AC 19 ms
38,596 KB
testcase_02 AC 36 ms
38,480 KB
testcase_03 AC 39 ms
38,568 KB
testcase_04 AC 36 ms
38,568 KB
testcase_05 AC 37 ms
38,520 KB
testcase_06 AC 31 ms
38,616 KB
testcase_07 AC 24 ms
38,636 KB
testcase_08 AC 35 ms
38,488 KB
testcase_09 AC 31 ms
38,472 KB
testcase_10 AC 37 ms
38,484 KB
testcase_11 AC 29 ms
38,696 KB
testcase_12 AC 35 ms
38,472 KB
testcase_13 AC 27 ms
38,484 KB
testcase_14 AC 16 ms
38,516 KB
testcase_15 AC 37 ms
38,700 KB
testcase_16 AC 37 ms
38,484 KB
testcase_17 AC 37 ms
38,484 KB
testcase_18 AC 38 ms
38,508 KB
testcase_19 AC 37 ms
38,696 KB
testcase_20 AC 16 ms
38,568 KB
testcase_21 AC 16 ms
38,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/302
// status:
// tag: [multi_choose]

#define SUBMIT
//#define DEBUG

#include <bits/stdc++.h>
using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_D = 1500;
const int MAX_K = 1500;

ui64 dp[(MAX_D + MAX_K - 1) + 1][MAX_K + 1];

// dp[i][j] i種類の品物を重複ありでj個選ぶ組み合わせの総数
// nC0 = 1
// 重複組合せではnHk = n+k-1Ck
// nCk = n-1Cr-1 + n-1Crの公式を用いる
// dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][r];

template <std::size_t N, std::size_t K, typename T>
void init_multi_choose(T dp[N][K], ui64 mod) {
    for (int i = 0; i < N; ++i) dp[i][0] = 1;

    for (int i = 0; i < N - 1; ++i) {
        for (int j = 1; j < K; ++j) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1] + dp[i][j]) % mod;
        }
    }
}

template <std::size_t N, std::size_t K, std::size_t Limit, typename T>
void init_multi_choose(T dp[N][K]) {
    for (int i = 0; i < N; ++i) dp[i][0] = 1;

    for (int i = 0; i < N - 1; ++i) {
        for (int j = 1; j < K; ++j) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1] + dp[i][j]);
            if (dp[i + 1][j] > Limit) dp[i + 1][j] = Limit;
        }
    }
}

const ui64 LIMIT = static_cast<ui64>(1e16);

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(3
58 62 1000
12 34 56
987 65 1234
)");
#endif
    init_multi_choose<MAX_D + MAX_K, MAX_K + 1, LIMIT>(dp);

    ui64 Q;
    stream >> Q;
    ui64 D, K, T;
    for (int i = 0; i < Q; ++i) {
        stream >> D >> K >> T;
        auto n_runs = dp[D + K - 1][K];

        if (T < n_runs) cout << "ZETUBOU" << endl;
        else cout << "AC" << endl;
    }

    return 0;
}
0