結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー tottoripapertottoripaper
提出日時 2017-03-24 23:18:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,625 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 165,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 03:43:49
合計ジャッジ時間 3,267 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int Gx, Gy, K;
ll Xs[100], Ys[100], Cs[100];

namespace tottori{
    // until C++17
    template <typename T, size_t N>
    constexpr size_t size(const T (&array)[N]){
        return N;
    }
};

template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
    T res = 1;
    while(n){
        if(n & 1){res = res * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <typename T>
T inverse(T n, T mod){
    return expt(n, mod-2, mod);
}

ll fact[410], inv[410];

// nCk
template <typename T>
T nCk(T n, T k, T mod = std::numeric_limits<T>::max()){
    if(n < k){return 0;}
    return fact[n] * inv[k] % mod * inv[n-k] % mod;
}

void initFactAndInv(ll mod){
    fact[0] = 1;
    inv[0] = 1;

    for(int i=1;i<tottori::size(fact);i++){
        fact[i] = fact[i-1] * i % mod;
        inv[i] = inverse(fact[i], mod);
    }
}

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

    initFactAndInv(1000000007ll);
    
    std::cin >> Gx >> Gy >> K;

    for(int i=0;i<K;++i){
        std::cin >> Xs[i] >> Ys[i] >> Cs[i];
    }

    ll res = 0ll;
    for(int i=0;i<=Cs[0];++i){
        for(int j=0;j<=Cs[1];++j){
            for(int k=0;k<=Cs[2];++k){
                for(int l=0;l<=Cs[3];++l){
                    for(int m=0;m<=Cs[4];++m){
                        ll cs[5] = {i, j, k, l, m};
                        ll x = 0ll, y = 0ll;
                        for(int a=0;a<5;++a){
                            x += 1ll * Xs[a] * cs[a];
                            y += 1ll * Ys[a] * cs[a];
                        }

                        // std::cout << x << " " << y << std::endl;

                        ll z = 1ll;
                        int sum = i + j + k + l + m, pr = 0;
                        for(int a=0;a<5;++a){
                            // std::cout << (sum - pr) << " " << cs[a] << std::endl;
                            z = z * nCk(1ll * sum - pr, cs[a], 1000000007ll) % 1000000007ll;
                            
                            pr += cs[a];
                        }
                        
                        if(x == Gx && y == Gy){
                            res = (res + z) % 1000000007ll;
                        }
                    }
                }
            }
        }
    }

    std::cout << res << std::endl;
}
0