結果

問題 No.243 出席番号(2)
ユーザー kenkooookenkoooo
提出日時 2015-07-11 10:30:06
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,182 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 73,344 KB
実行使用メモリ 252,976 KB
最終ジャッジ日時 2023-09-22 10:59:54
合計ジャッジ時間 13,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,804 KB
testcase_01 AC 122 ms
55,848 KB
testcase_02 AC 122 ms
55,480 KB
testcase_03 AC 230 ms
61,736 KB
testcase_04 MLE -
testcase_05 WA -
testcase_06 AC 222 ms
63,780 KB
testcase_07 RE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 RE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 RE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 RE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 AC 120 ms
55,508 KB
testcase_29 AC 120 ms
55,768 KB
testcase_30 AC 118 ms
55,464 KB
testcase_31 WA -
testcase_32 AC 122 ms
55,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	private final int MOD = 1000000007;

	public void solve() {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] hates = new int[N];
		for (int i = 0; i < N; i++) {
			hates[scanner.nextInt()]++;
		}
		scanner.close();

		// dp[i][j]:= i番目の出席番号までだけ見て、
		// j個の出席番号が嫌いな人に割り当てられている数
		long[][] dp = new long[N + 1][N + 1];
		dp[0][0] = 1;
		for (int i = 0; i < N; i++) {
			for (int j = N; j >= 0; j--) {
				dp[i + 1][j] = dp[i][j];
				if (j == 0) {
					continue;
				}
				dp[i + 1][j] += dp[i][j - 1] * hates[i];
				dp[i + 1][j] %= MOD;
			}
		}

		// factor[i] = i!
		long[] factor = new long[N + 1];
		factor[0] = 1;
		for (int i = 1; i <= N; i++) {
			factor[i] = factor[i - 1] * i;
			factor[i] %= MOD;
		}

		long ans = 0;
		for (int j = 0; j <= N; j++) {
			if (j % 2 == 0) {
				ans += dp[N][j] * factor[N - j] % MOD;
			} else {
				ans -= dp[N][j] * factor[N - j] % MOD;
				if (ans < 0) {
					ans += MOD;
				}
			}
		}
		System.out.println(ans);
	}

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