結果

問題 No.118 門松列(2)
ユーザー htensaihtensai
提出日時 2019-12-05 12:46:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 533 ms / 5,000 ms
コード長 949 bytes
コンパイル時間 3,612 ms
コンパイル使用メモリ 74,356 KB
実行使用メモリ 61,984 KB
最終ジャッジ日時 2023-08-22 18:08:52
合計ジャッジ時間 14,040 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
58,812 KB
testcase_01 AC 533 ms
60,444 KB
testcase_02 AC 497 ms
60,336 KB
testcase_03 AC 525 ms
60,460 KB
testcase_04 AC 500 ms
60,560 KB
testcase_05 AC 494 ms
61,984 KB
testcase_06 AC 124 ms
55,844 KB
testcase_07 AC 123 ms
55,828 KB
testcase_08 AC 124 ms
56,228 KB
testcase_09 AC 498 ms
60,596 KB
testcase_10 AC 295 ms
60,444 KB
testcase_11 AC 319 ms
60,528 KB
testcase_12 AC 266 ms
60,280 KB
testcase_13 AC 240 ms
59,212 KB
testcase_14 AC 483 ms
60,276 KB
testcase_15 AC 197 ms
56,992 KB
testcase_16 AC 435 ms
60,512 KB
testcase_17 AC 229 ms
59,772 KB
testcase_18 AC 320 ms
60,068 KB
testcase_19 AC 407 ms
60,664 KB
testcase_20 AC 390 ms
60,460 KB
testcase_21 AC 485 ms
60,588 KB
testcase_22 AC 311 ms
59,952 KB
testcase_23 AC 467 ms
60,356 KB
testcase_24 AC 341 ms
60,084 KB
testcase_25 AC 393 ms
59,928 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();
		    if (map.containsKey(x)) {
		        map.put(x, map.get(x) + 1);
		    } else {
		        map.put(x, 1);
		    }
		}
		int length = map.size();
		int[] arr = new int[length + 1];
		int[] sums = new int[length + 1];
		int[] totals = new int[length + 1];
		int idx = 1;
		for (int x : map.values()) {
		    arr[idx] = x;
		    sums[idx] = sums[idx - 1] + arr[idx];
		    sums[idx] %= MOD;
		    totals[idx] = (int)((long)(arr[idx]) * sums[idx - 1] + totals[idx - 1] % MOD);
		    idx++;
		}
		long ans = 0;
		for (int i = length; i >= 1; i--) {
		    ans += (long)(arr[i]) * totals[i - 1];
		    ans %= MOD;
		}
	    System.out.println(ans);
	}
}
	
0