結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー |
|
提出日時 | 2017-03-31 05:36:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 1,339 bytes |
コンパイル時間 | 1,763 ms |
コンパイル使用メモリ | 168,440 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 03:54:15 |
合計ジャッジ時間 | 2,400 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)#define all(x) (x).begin(),(x).end()#define pb push_back#define fi first#define se secondconst ll mod = 1e9+7;ll mod_pow(ll x, ll n){ll pw[32];pw[0]=x%mod;for(int i=1; i<32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;ll ret=1;rep(i,32)if(n>>i&1) (ret*=pw[i])%=mod;return ret;}ll mod_inv(ll x){return mod_pow(x,mod-2);}int gx,gy,k;int x[5],y[5],n[5];ll fact[100];ll ans = 0;int num[5];void dfs(int depth){if(depth == k){int X=0,Y=0;rep(i,k){X += num[i]*x[i];Y += num[i]*y[i];}if(X == gx && Y == gy){int sum = 0;rep(i,k) sum += num[i];ll add = fact[sum];rep(i,k) (add*=mod_inv(fact[num[i]]))%=mod;(ans+=add)%=mod;}return;}rep(i,n[depth]+1){num[depth] = i;dfs(depth+1);}}int main(){fact[0]=1;for(ll i=1; i<100; ++i) fact[i] = (fact[i-1]*i)%mod;cin >>gx >>gy >>k;rep(i,k) cin >>x[i] >>y[i] >>n[i];dfs(0);cout << ans << endl;return 0;}