結果

問題 No.118 門松列(2)
ユーザー 37zigen
提出日時 2020-02-18 12:03:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 605 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 77,992 KB
実行使用メモリ 48,188 KB
最終ジャッジ日時 2024-10-06 15:29:34
合計ジャッジ時間 13,033 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	final long m=(long)1e9+7;
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] cnt=new int[101];
		for(int i=0;i<N;++i) {
			int a=sc.nextInt();
			cnt[a]++;
		}
		long[] dp=new long[3];
		for(int i=0;i<cnt.length;++i) {
			if(cnt[i]==0)continue;
			dp[2]+=dp[1]*cnt[i]%m;
			dp[1]+=dp[0]*cnt[i]%m;
			dp[0]+=cnt[i];
			for(int j=0;j<3;++j)dp[j]%=m;
		}
		System.out.println(dp[2]);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0