結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー tottoripapertottoripaper
提出日時 2017-03-24 23:18:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,625 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 167,972 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 00:01:55
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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