結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー |
![]() |
提出日時 | 2017-03-24 23:10:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 650 ms / 2,000 ms |
コード長 | 1,258 bytes |
コンパイル時間 | 1,387 ms |
コンパイル使用メモリ | 170,248 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 23:34:07 |
合計ジャッジ時間 | 9,858 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) #define ALL(x) x.begin(),x.end() template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int gx,gy,N,K; vector<int> X(K),Y(K),C(K); ll fact [101]; const ll MOD = 1e9 + 7; ll mod_pow(ll x,ll y = MOD - 2) { ll res = 1; while(y){ if(y & 1) (res *= x) %= MOD; (x *= x) %= MOD; y >>= 1; } return res; } ll dfs(int idx,vector<int>& v) { if(idx == K){ int x = 0,y = 0; ll sum = accumulate(ALL(v),0ll); ll res = fact [sum]; FOR(i,0,K){ (res *= mod_pow(fact [v [i]])) %= MOD; x += X [i] * v [i]; y += Y [i] * v [i]; } if(x != gx || y != gy) return 0; return res; } ll res = 0; FOR(i,0,C [idx] + 1){ v.push_back(i); (res += dfs(idx + 1,v)) %= MOD; v.pop_back(); } return res; } int main() { scanf("%d%d%d",&gx,&gy,&K); X.assign(K,0); Y.assign(K,0); C.assign(K,0); FOR(i,0,K){ scanf("%d%d%d",&X [i],&Y [i],&C [i]); N += C [i]; } fact [0] = 1; FOR(i,1,101){ fact [i] = fact [i - 1] * i % MOD; } vector<int> v; printf("%lld\n",dfs(0,v)); return 0; }