結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー masamasa
提出日時 2017-04-18 17:14:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 75,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 13:23:06
合計ジャッジ時間 3,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

using namespace std;

const int mod = 1e9;

int calc(vector<int> uses) {
	int sum = accumulate(uses.begin(), uses.end(), 0);

	vector<int> nums;
	for (int i = sum; i > 1; i--) {
		nums.emplace_back(i);
	}

	for (auto e : uses) {
		for (int i = e; i > 1; i--) {
			int tmp = i;
			for (int j = 0; j < nums.size(); j++) {
				int gcd = __gcd(tmp, nums[j]);
				nums[j] /= gcd;
				tmp /= gcd;
				if (tmp == 1) {
					break;
				}
			}
		}
	}

	long long ret = 1;
	for (auto e : nums) {
		ret = (ret * e) % mod;
	}

	return ret;
}


int main() {
	int gx, gy, k;
	cin >> gx >> gy >> k;

	int limit = 1;
	vector<int> x(k), y(k), n(k);
	for (int i = 0; i < k; i++) {
		cin >> x[i] >> y[i] >> n[i];
		limit *= n[i] + 1;
	}

	long long ans = 0;
	for (int i = 0; i < limit; i++) {
		int tmp = i;
		int pos_x = 0;
		int pos_y = 0;

		vector<int> uses(k, 0);

		for (int j = 0; j < k; j++) {
			uses[j] = tmp % (n[j] + 1);
			pos_x += uses[j] * x[j];
			pos_y += uses[j] * y[j];
			tmp /= (n[j] + 1);
		}
		if (pos_x != gx || pos_y != gy) {
			continue;
		}

		ans = (ans + calc(uses)) % mod;
	}

	cout << ans << endl;
	return 0;
}
0