結果

問題 No.243 出席番号(2)
ユーザー kenkooookenkoooo
提出日時 2015-07-11 10:17:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,180 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 78,880 KB
実行使用メモリ 253,116 KB
最終ジャッジ日時 2023-09-22 10:55:19
合計ジャッジ時間 20,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 135 ms
55,672 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 MLE -
testcase_05 WA -
testcase_06 MLE -
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 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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 - 1; j >= 0; j--) {
				dp[i + 1][j + 1] = dp[i][j + 1];
				dp[i + 1][j + 1] += dp[i][j] * hates[i];
				dp[j + 1][i + 1] %= 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 += (long) dp[N][j] * factor[N - j];
				ans %= MOD;
			} else {
				ans -= ((long) dp[N][j] * factor[N - j]);
				while (ans < 0) {
					ans += MOD;
				}
			}
		}
		System.out.println(ans);
	}

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