結果

問題 No.243 出席番号(2)
ユーザー kenkooookenkoooo
提出日時 2015-07-11 10:34:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 74,136 KB
実行使用メモリ 62,368 KB
最終ジャッジ日時 2023-09-22 11:06:31
合計ジャッジ時間 11,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,796 KB
testcase_01 AC 126 ms
55,984 KB
testcase_02 AC 122 ms
56,372 KB
testcase_03 AC 213 ms
56,684 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 231 ms
57,220 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 254 ms
58,896 KB
testcase_11 AC 233 ms
59,024 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 123 ms
55,528 KB
testcase_29 AC 122 ms
55,764 KB
testcase_30 AC 123 ms
56,036 KB
testcase_31 WA -
testcase_32 AC 126 ms
56,124 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++) {
			int A = scanner.nextInt();
			if (A >= N) {
				continue;
			}
			hates[A]++;
		}
		scanner.close();

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

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