結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,056 KB
testcase_01 AC 118 ms
55,760 KB
testcase_02 AC 117 ms
55,560 KB
testcase_03 AC 223 ms
56,616 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 226 ms
56,860 KB
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 235 ms
58,736 KB
testcase_11 AC 233 ms
58,508 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 121 ms
55,812 KB
testcase_29 AC 121 ms
55,744 KB
testcase_30 AC 120 ms
55,644 KB
testcase_31 WA -
testcase_32 AC 120 ms
55,928 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];
		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