結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー vjudge1
提出日時 2025-02-21 21:00:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 192,204 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-21 21:00:35
合計ジャッジ時間 3,212 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define all(v)v.begin(),v.end()
#define rall(v)v.rbegin(),v.rend()
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T>&v){for(auto&i:v)O<<i<<' ';return O;}
namespace AC{
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);
	}
}
void solve(){
	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;
}
}
signed main(){
	int t=1;
	//cin>>t;
	while(t--)AC::solve();
}
0