結果
| 問題 |
No.498 ワープクリスタル (給料日編)
|
| コンテスト | |
| ユーザー |
sekiya9311
|
| 提出日時 | 2017-03-25 00:25:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 3,849 bytes |
| コンパイル時間 | 1,219 ms |
| コンパイル使用メモリ | 119,504 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 03:18:17 |
| 合計ジャッジ時間 | 1,913 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#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;
}
sekiya9311