結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー PachicobuePachicobue
提出日時 2017-08-30 22:49:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,701 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 166,836 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-06 11:30:02
合計ジャッジ時間 2,697 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #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 = (ll)1e9 + 7LL;

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

// }}}

constexpr int MAX = 100;
ll combi[MAX + 1][MAX + 1];

ll comb(ll i, ll j, ll k, ll l, ll m)
{
    ll prod = 1;
    ll sum = i + j + k + l + m;
    prod = (prod * combi[sum][i]) % MOD;
    sum -= i;
    prod = (prod * combi[sum][j]) % MOD;
    sum -= j;
    prod = (prod * combi[sum][k]) % MOD;
    sum -= k;
    prod = (prod * combi[sum][l]) % MOD;
    return prod;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    combi[0][0] = 1;
    for (ll i = 1; i <= MAX; i++) {
        for (ll j = 0; j <= MAX; j++) {
            if (j == 0) {
                combi[i][j] = 1;
            } else {
                combi[i][j] = (combi[i - 1][j - 1] + combi[i - 1][j]) % MOD;
            }
        }
    }

    ll gx, gy;
    cin >> gx >> gy;
    ll k;
    cin >> k;
    array<ll, 5> x;
    array<ll, 5> y;
    array<ll, 5> num;
    for (ll i = 0; i < 5; i++) {
        if (i < k) {
            cin >> x[i] >> y[i] >> num[i];
        } else {
            x[i] = 0;
            y[i] = 0;
            num[i] = 0;
        }
    }

    ll cnt = 0;
    for (ll i = 0; i <= num[0]; i++) {
        const ll x0 = x[0] * i;
        const ll y0 = y[0] * i;
        for (ll j = 0; j <= num[1]; j++) {
            const ll x1 = x[1] * j;
            const ll y1 = y[1] * j;
            for (ll k = 0; k <= num[2]; k++) {
                const ll x2 = x[2] * k;
                const ll y2 = y[2] * k;
                for (ll l = 0; l <= num[3]; l++) {
                    const ll x3 = x[3] * l;
                    const ll y3 = y[3] * l;
                    for (ll m = 0; m <= num[4]; m++) {
                        const ll X = x0 + x1 + x2 + x3 + x[4] * m;
                        const ll Y = y0 + y1 + y2 + y3 + y[4] * m;
                        if (X == gx and Y == gy) {
                            cnt += comb(i, j, k, l, m);
                            cnt = cnt % MOD;
                        }
                    }
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}
0