結果

問題 No.118 門松列(2)
ユーザー tentententen
提出日時 2020-11-17 20:03:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 531 ms / 5,000 ms
コード長 1,022 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 75,272 KB
実行使用メモリ 60,952 KB
最終ジャッジ日時 2023-09-30 14:24:15
合計ジャッジ時間 13,306 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 221 ms
59,200 KB
testcase_01 AC 526 ms
60,712 KB
testcase_02 AC 499 ms
60,684 KB
testcase_03 AC 531 ms
60,508 KB
testcase_04 AC 517 ms
60,580 KB
testcase_05 AC 512 ms
60,512 KB
testcase_06 AC 125 ms
55,764 KB
testcase_07 AC 123 ms
55,712 KB
testcase_08 AC 125 ms
55,784 KB
testcase_09 AC 506 ms
60,284 KB
testcase_10 AC 293 ms
60,952 KB
testcase_11 AC 321 ms
60,308 KB
testcase_12 AC 267 ms
60,092 KB
testcase_13 AC 236 ms
59,628 KB
testcase_14 AC 487 ms
58,808 KB
testcase_15 AC 197 ms
58,516 KB
testcase_16 AC 435 ms
60,328 KB
testcase_17 AC 237 ms
59,880 KB
testcase_18 AC 329 ms
60,740 KB
testcase_19 AC 408 ms
60,280 KB
testcase_20 AC 380 ms
60,512 KB
testcase_21 AC 489 ms
59,992 KB
testcase_22 AC 313 ms
60,316 KB
testcase_23 AC 478 ms
60,280 KB
testcase_24 AC 333 ms
60,064 KB
testcase_25 AC 400 ms
60,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            map.put(x, map.getOrDefault(x, 0) + 1);
        }
        long[] comb3 = new long[n + 1];
        long[] comb2 = new long[n + 1];
        for (int i = 3; i <= n; i++) {
            comb3[i] = 1;
            for (long j = 0; j < 3; j++) {
                comb3[i] *= i - j;
            }
            comb3[i] /= 6;
            comb2[i] = 1;
            for (long j = 0; j < 2; j++) {
                comb2[i] *= i - j;
            }
            comb2[i] /= 2;
        }
        comb2[2] = 1;
        long ans = comb3[n];
        for (int x : map.values()) {
            ans -= comb3[x];
            ans -= comb2[x] * (n - x);
        }
        System.out.println(ans % MOD);
    }
}
0