結果

問題 No.118 門松列(2)
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 17:27:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 3,870 ms
コンパイル使用メモリ 74,976 KB
実行使用メモリ 63,200 KB
最終ジャッジ日時 2023-09-26 02:12:11
合計ジャッジ時間 14,848 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 122 ms
56,092 KB
testcase_07 AC 121 ms
55,852 KB
testcase_08 AC 123 ms
56,176 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 201 ms
58,848 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()];
		long sum = 0;
		{
			int i = 0;
			for(final Entry<Long, Integer> entry : counts.entrySet()){
				count_array[i] = entry.getValue();
				sum += count_array[i];
				
				i++;
			}
		}
		
		long answer = 0;
		long forward_sum = 0, backward_sum = sum;
		for(int i = 0; i < count_array.length; i++){
			backward_sum -= count_array[i];
			
			//System.out.println(forward_sum + " " + backward_sum);
			answer += forward_sum * count_array[i] * backward_sum;
			answer %= MOD;
			
			forward_sum += count_array[i];
		}
		
		System.out.println(answer);
		
	}
	
}
0