結果

問題 No.1904 Never giving up!
ユーザー tentententen
提出日時 2022-08-09 18:04:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,371 bytes
コンパイル時間 4,414 ms
コンパイル使用メモリ 77,864 KB
実行使用メモリ 53,560 KB
最終ジャッジ日時 2023-10-20 03:01:27
合計ジャッジ時間 6,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
53,540 KB
testcase_01 AC 59 ms
51,560 KB
testcase_02 AC 59 ms
53,536 KB
testcase_03 AC 58 ms
53,536 KB
testcase_04 AC 60 ms
53,544 KB
testcase_05 AC 60 ms
53,548 KB
testcase_06 AC 59 ms
53,536 KB
testcase_07 AC 57 ms
52,480 KB
testcase_08 AC 58 ms
53,548 KB
testcase_09 AC 56 ms
53,560 KB
testcase_10 AC 60 ms
53,548 KB
testcase_11 AC 60 ms
51,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            counts.put(x, counts.getOrDefault(x, 0) + 1);
        }
        long ans = fact(n);
        for (int x : counts.values()) {
            ans /= fact(x);
        }
        System.out.println(ans);
    }
    
    static long fact(int x) {
        if (x == 0) {
            return 1;
        } else {
            return fact(x - 1) * x;
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0