結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー sekiya9311sekiya9311
提出日時 2017-03-25 00:23:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 3,849 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 115,836 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 07:20:13
合計ジャッジ時間 2,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

const int MAX = 1000;
int gx, gy, K, N = 0;
LL x[MAX], y[MAX];
int cnt[MAX];
const int MAX_P = 1e5 + 10;

template<int mod>
class ModCalc {
private:
    const int defnum = -1;
public:
    ModCalc() { }
    int add(int a, int b) {
        a += b;
        while (a < 0) a += mod;
        while (a >= mod) a -= mod;
        return a;
    }
    int mul(int a, int b) {
        return (long long)a * b % mod;
    }
    int pow(int a, int p) {
        int res = 1;
        while (p > 0) {
            if (p & 1) res = this->mul(res, a);
            a = this->mul(a, a);
            p >>= 1;
        }
        return res;
    }
    int inverse(int a) {
        return this->pow(a, mod - 2);
    }
};

ModCalc<MOD> mc;
int memoFact[MAX], memoInvFact[MAX];

int fact(int n) {
    if (memoFact[n] != -1) return memoFact[n];
    return memoFact[n] = (n == 0 ? 1 : mc.mul(n, fact(n - 1)));
}

int invFact(int n) {
    if (memoInvFact[n] != -1) return memoInvFact[n];
    return memoInvFact[n] = mc.inverse(fact(n));
}

LL comb(LL n, LL r) {
    return mc.mul(mc.mul(fact(n), invFact(r)), invFact(n - r));
}

// M個の物をN人で分ける
LL combWithRepetition(LL M, LL N) {
    return comb(M + N - 1, N - 1);
}

//最初に呼んで♪
void init() {
    memset(memoFact, -1, sizeof(memoFact));
    memset(memoInvFact, -1, sizeof(memoInvFact));
    memoFact[0] = 1;
    for (int i = 0; i < MAX; i++) {
        fact(i);
        invFact(i);
    }
}

int main() {
    init();
    scanf("%d%d%d", &gx, &gy, &K);
    REP(i, K) {
        scanf("%lld%lld%d", x + i, y + i, cnt + i);
    }
    LL ans = 0;
    REP(i, cnt[0] + 1) REP(j, cnt[1] + 1) REP(k, cnt[2] + 1) REP(l, cnt[3] + 1) REP(m, cnt[4] + 1) {
        LL X = x[0] * i + x[1] * j + x[2] * k + x[3] * l + x[4] * m;
        LL Y = y[0] * i + y[1] * j + y[2] * k + y[3] * l + y[4] * m;
        //cout<<X<<Y<<endl;
        if (X == gx && Y == gy) {
            LL inv = mc.mul(invFact(i), mc.mul(invFact(j), mc.mul(invFact(k), mc.mul(invFact(l), invFact(m)))));
            (ans += ((LL)fact(i + j + k + l + m) * inv)) %= MOD;
        }
    }
    cout << ans << endl;
}
0