結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー |
|
提出日時 | 2017-03-24 22:45:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,171 bytes |
コンパイル時間 | 579 ms |
コンパイル使用メモリ | 75,548 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 22:12:48 |
合計ジャッジ時間 | 1,506 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <vector> #include <string> #include <set> #include <map> #include <tuple> using namespace std; const int mod = 1e9 + 7; int fact[1000]; int invfact[1000]; int inv[1000]; int gx, gy, k; int x[5], y[5], c[5]; int use[5]; int ans; void dfs(int k, int n) { if (k == n) { int xx = 0; int yy = 0; int pattern = 1; int s = 0; for (int i = 0; i < n; i++) { xx += x[i] * use[i]; yy += y[i] * use[i]; s += use[i]; pattern = 1LL * pattern * invfact[use[i]] % mod; } pattern = 1LL * pattern * fact[s] % mod; if (xx == gx && yy == gy) { ans += pattern; ans %= mod; } return; } for (int i = 0; i <= c[k]; i++) { use[k] = i; dfs(k + 1, n); } } int main() { inv[1] = 1; for (int i = 2; i < 1000; i++) { inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod; } fact[0] = 1; invfact[0] = 1; for (int i = 1; i < 1000; i++) { fact[i] = 1LL * i * fact[i - 1] % mod; invfact[i] = 1LL * inv[i] * invfact[i - 1] % mod; } cin >> gx >> gy >> k; for (int i = 0; i < k; i++) { cin >> x[i] >> y[i] >> c[i]; } dfs(0, k); cout << ans << endl; }