結果

問題 No.963 門松列列(2)
ユーザー 37zigen37zigen
提出日時 2019-12-11 22:44:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 74,232 KB
実行使用メモリ 62,136 KB
最終ジャッジ日時 2023-09-08 03:37:52
合計ジャッジ時間 7,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

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

	final long MOD = 1000000007;

	void solver() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if (N == 1 || N == 2) {
			System.out.println(0);
			return;
		}
		long[] c = new long[N + 2];
		c[0] = 1;
		c[1] = 2;
		c[2] = 1;
		long inv_4=250000002;
		
		long[] dp = new long[N + 1];// dp[i]:N=iの時の門松列の数
		dp[0] = 2;
		dp[1] = 2;
		dp[2] = 2;
		for (int i = 2; i < N; i++) {
			for (int j = 0; j <= i; j++) {
				dp[i + 1] += dp[j] * dp[i - j]  % MOD * c[j] % MOD*inv_4;
				dp[i + 1] %= MOD;
				if (dp[i + 1] < 0 || c[j] <= 0) {
					throw new AssertionError("error");
				}
			}
			for (int j = i + 1; j >= 0; j--) {
				if (j != 0) {
					c[j] = c[j] + c[j - 1];
				} else {
					c[j] = 1;
				}
				c[j] %= MOD;
				if (c[j] < 0)
					throw new AssertionError();
			}
		}
		System.out.println(dp[N]);
		sc.close();
	}
}
0