結果
問題 |
No.498 ワープクリスタル (給料日編)
|
ユーザー |
![]() |
提出日時 | 2019-02-28 20:45:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,713 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 76,664 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 11:49:50 |
合計ジャッジ時間 | 1,504 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <iostream> #include <algorithm> #include <cstring> #include <sstream> #include <map> #include <queue> #include <set> #include <vector> #include <stack> #include <cstdio> #include <cmath> #define mk make_pair #define pb push_back #define printf printf_s #define scanf scanf_s using namespace std; typedef long long int ll; typedef pair<ll, ll> pos; const ll MOD = 1000000007, N = 200010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838; ll mn(ll a, ll b) { if (a == -1)return b; if (b == -1)return a; return min(a, b); } ll gcd(ll v1, ll v2) { if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2); } ll pw(ll v1, ll v2) { ll v3 = 1; while (v2 > 0) { if (v2 % 2)v3 = (v3*v1) % MOD; v1 = (v1*v1) % MOD; v2 /= 2; } return v3; } struct ab { ll a, b; bool operator<(const ab& right) const { return right.b*a - right.a*b < 0; } }; ll ft[100], rv[100], k,ans=0,lst[6]; pos g; pair<pos, ll> n[16]; void src(pos cp,ll ind) { if (ind == k) { if (cp != g)return; ll v1 = 0,v2=1; for (int i = 0; i < k; i++) { v2 = (v2*rv[lst[i]]) % MOD; v1 += lst[i]; } v2 = (v2*ft[v1]) % MOD; ans = (ans + v2) % MOD; return; } for (int i = 0; i <= n[ind].second; i++) { lst[ind] = i; pos np = mk(cp.first + i * n[ind].first.first, cp.second + i * n[ind].first.second); src(np, ind + 1); } } int main() { ft[0] = rv[0] = 1; for (int i = 1; i < 100; i++) { ft[i] = (ft[i - 1] * i) % MOD; rv[i] = pw(ft[i], MOD - 2); } cin >> g.first >> g.second >> k; for (int i = 0; i < k; i++)cin >> n[i].first.first >> n[i].first.second >> n[i].second; src(mk(0, 0), 0); cout << ans << endl; return 0; }