結果

問題 No.118 門松列(2)
ユーザー kuuso1kuuso1
提出日時 2015-01-06 23:32:04
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,162 bytes
コンパイル時間 3,534 ms
コンパイル使用メモリ 104,524 KB
実行使用メモリ 51,156 KB
最終ジャッジ日時 2023-09-03 22:08:51
合計ジャッジ時間 8,207 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
45,944 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 118 ms
43,620 KB
testcase_07 AC 118 ms
43,564 KB
testcase_08 AC 120 ms
43,520 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Dictionary<int,int> D=new Dictionary<int,int>();
		for(int i=0;i<N;i++){
			if(!D.ContainsKey(A[i]))D.Add(A[i],0);
			D[A[i]]++;
		}
		if(D.Keys.Count<3){
			Console.WriteLine(0);
			return;
		}
		
		long ans=cal_nCrMod(D.Keys.Count,3);
		foreach(int k in D.Keys){
			ans*=D[k];
			ans%=mod;
		}
		
		Console.WriteLine(ans);
	}
	int N;
	int[] A;
	public Sol(){
		N=ri();
		A=ria();
		
		
		FM=new long[Max];
		FM[0]=1;
		for(int x=1;x<Max;x++)FM[x]=(FM[x-1]*x)%mod;
	}

	long cal_nCrMod(long n,long r){
		if(n<r)return 0;
		if(n<0)return 0;
		if(r<0)return 0;
		if(n==0||r==n||r==0)return 1;
		long a=FactorialMod(n);
		long b=InvMod(FactorialMod(r));
		long c=InvMod(FactorialMod(n-r));
		long ans=(((a*b)%mod)*c)%mod;
		return ans;
	}
	
	static long Max=(int)3e6;
	static long mod=(long)(1e9+7);
	
	long[] FM;
	long FactorialMod(long n){
		/*
		if(n<2)return 1;
		long ret=n*FactorialMod(n-1);
		ret%=mod;
		return ret;
		*/
		return FM[(int)n];
	}
	
	long InvMod(long n){
		if(n>mod)n%=mod;
		if(n==0)return 0;
		//(mod-2)乗を返す
		List<long> L=new List<long>();
		
		int idx=0;
		while(mod>(0x1<<idx))idx++;
		long[] Table=new long[idx];
		Table[0]=n;
		for(int i=1;i<idx;i++){
			Table[i]=Table[i-1]*Table[i-1];
			Table[i]%=mod;
		}
		
		
		long ret=1;
		for(int i=0;i<idx;i++){
			if(( (mod-2)&(0x1<<i)) >0){
				ret*=Table[i];
				ret%=mod;
			}
		}
		
		return ret;
		
		
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0