結果

問題 No.584 赤、緑、青の色塗り
ユーザー 37zigen37zigen
提出日時 2017-11-08 05:00:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,854 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 74,564 KB
実行使用メモリ 56,468 KB
最終ジャッジ日時 2023-08-15 20:32:46
合計ジャッジ時間 6,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,772 KB
testcase_01 AC 121 ms
56,008 KB
testcase_02 AC 123 ms
56,468 KB
testcase_03 AC 123 ms
55,948 KB
testcase_04 AC 123 ms
55,676 KB
testcase_05 AC 124 ms
53,944 KB
testcase_06 AC 124 ms
56,052 KB
testcase_07 AC 124 ms
55,656 KB
testcase_08 AC 121 ms
55,652 KB
testcase_09 AC 119 ms
53,776 KB
testcase_10 AC 122 ms
55,676 KB
testcase_11 AC 121 ms
55,600 KB
testcase_12 AC 122 ms
55,840 KB
testcase_13 AC 121 ms
55,800 KB
testcase_14 AC 131 ms
55,660 KB
testcase_15 AC 128 ms
55,692 KB
testcase_16 AC 131 ms
55,460 KB
testcase_17 AC 132 ms
55,708 KB
testcase_18 AC 124 ms
55,708 KB
testcase_19 AC 180 ms
56,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	static final long MODULO = 1_000_000_000 + 7;
	static final int MAXN = 3000;
	static long[] fac = new long[2 * MAXN];
	static long[] invfac = new long[2 * MAXN];
	static long[] inv = new long[2 * MAXN];
	{
		fac[0] = fac[1] = inv[0] = inv[1] = invfac[0] = invfac[1] = 1;
		for (int i = 2; i < 2 * MAXN; ++i) {
			fac[i] = fac[i - 1] * i % MODULO;
			inv[i] = MODULO - inv[(int) MODULO % i] * (MODULO / i) % MODULO;
			invfac[i] = invfac[i - 1] * inv[i] % MODULO;
		}
	}

	static long comb(int n, int k) {
		return fac[n] * invfac[n - k] % MODULO * invfac[k] % MODULO;
	}

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = a * a % MODULO) {
			if (n % 2 == 1) {
				ret = ret * a % MODULO;
			}
		}
		return ret;
	}

	static void solve(int n, int[] a) {
		long ans = 0;
		int t = a[0] + a[1] + a[2];
		for (int u = 0; u <= t; u += 2) {
			int v = t - u;
			if (u / 2 + v - 1 > n - t)
				continue;
			long comb = comb(u / 2 + v + (n - t - (u / 2 + v - 1)), u / 2 + v) * comb(u / 2 + v, v) % MODULO;
			for (int i = Math.max(0, a[0] - v); i <= Math.min(u / 2, a[0]); ++i) {
				int a1 = a[1] - (u / 2 - i);
				int a2 = a[2] - (u / 2 - i);
				if (a1 < 0 || a2 < 0)
					continue;
				long nc = comb * pow(2, u / 2) % MODULO;
				nc = nc * comb(u / 2, i) % MODULO * comb(v, a[0] - i) % MODULO;
				nc = nc * comb(a1 + a2, a1) % MODULO;
				ans = (ans + nc) % MODULO;
			}
		}
		System.out.println(ans);
	}

	static void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[3];
		for (int i = 0; i < 3; ++i) {
			a[i] = sc.nextInt();
		}
		solve(n, a);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0