結果

問題 No.584 赤、緑、青の色塗り
ユーザー square1001square1001
提出日時 2018-01-21 17:25:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 83,708 KB
実行使用メモリ 37,536 KB
最終ジャッジ日時 2023-08-26 19:43:09
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
37,308 KB
testcase_01 AC 30 ms
37,396 KB
testcase_02 AC 29 ms
37,304 KB
testcase_03 AC 30 ms
37,292 KB
testcase_04 AC 30 ms
37,292 KB
testcase_05 AC 29 ms
37,344 KB
testcase_06 AC 29 ms
37,536 KB
testcase_07 AC 29 ms
37,312 KB
testcase_08 AC 29 ms
37,468 KB
testcase_09 AC 30 ms
37,532 KB
testcase_10 AC 30 ms
37,392 KB
testcase_11 AC 30 ms
37,436 KB
testcase_12 AC 30 ms
37,348 KB
testcase_13 AC 30 ms
37,284 KB
testcase_14 AC 32 ms
37,388 KB
testcase_15 AC 29 ms
37,392 KB
testcase_16 AC 31 ms
37,332 KB
testcase_17 AC 30 ms
37,320 KB
testcase_18 AC 30 ms
37,340 KB
testcase_19 AC 405 ms
37,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 1000000007;
int N, R, G, B, comb[3009][3009];
int main() {
	comb[0][0] = 1;
	for (int i = 1; i <= 3000; i++) {
		for (int j = 0; j <= i; j++) {
			comb[i][j] = comb[i - 1][j];
			if (j >= 1) comb[i][j] += comb[i - 1][j - 1];
			if (comb[i][j] >= mod) comb[i][j] -= mod;
		}
	}
	cin >> N >> R >> G >> B;
	if (R > G) swap(R, G);
	if (R > B) swap(R, B);
	if (G > B) swap(G, B);
	int ret = 0, pw = 1;
	for (int two = 0; 2 * two <= R + G + B; two++) {
		int one = R + G + B - 2 * two;
		if (3 * two + 2 * one >= N + 2) {
			pw = 2 * pw % mod;
			continue;
		}
		int res = 0;
		for (int i = 0; i <= R; i++) {
			for (int j = 0; j <= G; j++) {
				int k = 2 * two - i - j;
				if (0 <= k && k <= B && two - i >= 0 && two - j >= 0 && two - k >= 0) {
					int a = two - i, b = two - j, c = two - k;
					res = (res + 1LL * comb[two][a] * comb[two - a][b] % mod * comb[one][R - i] % mod * comb[one - R + i][G - j]) % mod;
				}
			}
		}
		ret = (ret + 1LL * res * comb[N + 1 - two * 2 - one][two] % mod * comb[N + 1 - two * 3 - one][one] % mod * pw) % mod;
		pw = 2 * pw % mod;
	}
	cout << ret << endl;
	return 0;
}
0