結果

問題 No.118 門松列(2)
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 16:54:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 3,846 ms
コンパイル使用メモリ 75,108 KB
実行使用メモリ 62,128 KB
最終ジャッジ日時 2023-09-26 02:09:45
合計ジャッジ時間 14,865 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 120 ms
56,344 KB
testcase_07 AC 120 ms
55,876 KB
testcase_08 AC 121 ms
55,748 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 196 ms
58,676 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long MOD = 1000000009;
		
		Map<Long, Integer> counts = new TreeMap<Long, Integer>();
		
		for(int i = 0; i < N; i++){
			final long L = sc.nextLong();
			
			if(!counts.containsKey(L)){
				counts.put(L, 0);
			}
			counts.put(L, counts.get(L) + 1);
		}
		
		long[] count_array = new long[counts.size()];
		{
			int i = 0;
			for(final Entry<Long, Integer> entry : counts.entrySet()){
				count_array[i] = entry.getValue();
				
				i++;
			}
		}
		long[] sum_array = new long[count_array.length];
		for(int i = 1; i < count_array.length; i++){
			sum_array[i] = sum_array[i - 1] + count_array[i - 1];
		}
		long[] sum_array_rev = new long[count_array.length];
		for(int i = count_array.length - 2; i >= 0; i--){
			sum_array_rev[i] = sum_array_rev[i + 1] + count_array[i + 1];
		}
		
		long answer = 0;
		for(int i = 0; i < count_array.length; i++){
			answer += count_array[i] * sum_array[i] * sum_array_rev[i];
			answer %= MOD;
		}
		
		System.out.println(answer);
		
	}
	
}
0