結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー pekempeypekempey
提出日時 2017-03-24 22:43:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 75,140 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 01:49:28
合計ジャッジ時間 2,401 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 24 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
	}
	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;
}
0