結果

問題 No.118 門松列(2)
ユーザー crazybbb3crazybbb3
提出日時 2017-01-31 00:19:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 2,201 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 90,816 KB
実行使用メモリ 57,184 KB
最終ジャッジ日時 2023-08-25 15:27:33
合計ジャッジ時間 8,238 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
52,548 KB
testcase_01 AC 215 ms
56,800 KB
testcase_02 AC 216 ms
56,624 KB
testcase_03 AC 222 ms
57,184 KB
testcase_04 AC 221 ms
56,836 KB
testcase_05 AC 217 ms
56,784 KB
testcase_06 AC 50 ms
50,084 KB
testcase_07 AC 50 ms
47,940 KB
testcase_08 AC 51 ms
49,924 KB
testcase_09 AC 215 ms
56,884 KB
testcase_10 AC 143 ms
53,572 KB
testcase_11 AC 152 ms
56,724 KB
testcase_12 AC 138 ms
54,052 KB
testcase_13 AC 120 ms
53,132 KB
testcase_14 AC 210 ms
56,696 KB
testcase_15 AC 100 ms
52,936 KB
testcase_16 AC 189 ms
56,808 KB
testcase_17 AC 136 ms
53,148 KB
testcase_18 AC 153 ms
56,048 KB
testcase_19 AC 165 ms
56,176 KB
testcase_20 AC 167 ms
54,720 KB
testcase_21 AC 201 ms
56,972 KB
testcase_22 AC 146 ms
53,836 KB
testcase_23 AC 201 ms
54,916 KB
testcase_24 AC 154 ms
56,208 KB
testcase_25 AC 166 ms
56,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = ni();
            map.merge(a, 1, (x, y) -> x + y);
        }

        long MOD = 1000000007;

        ArrayList<Integer> list = new ArrayList<>(map.values());
        int m = list.size();
        long ans = 0;
        for (int i = 0; i < m; i++) {
            for (int j = i + 1; j < m; j++) {
                for (int k = j + 1; k < m; k++) {
                    ans = (ans + (long) list.get(i) * list.get(j) * list.get(k)) % MOD;
                }
            }
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0