結果

問題 No.329 全射
ユーザー kuuso1kuuso1
提出日時 2015-12-22 02:17:49
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,457 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 112,176 KB
実行使用メモリ 36,972 KB
最終ジャッジ日時 2023-10-18 22:27:11
合計ジャッジ時間 5,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Linq;
using System.Text;

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

class Sol{
	public void Solve(){
		
checked{
		int[][] WF=new int[N][];
		for(int i=0;i<N;i++){
			WF[i]=new int[N];
		}
		
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(i==j||Mp[i,j])WF[i][j]=Math.Min(A[i],A[j]);
			}
		}
		
		for(int k=0;k<N;k++){
			for(int i=0;i<N;i++){
				for(int j=0;j<N;j++){
					WF[i][j]=Math.Max(WF[i][j],Math.Min(WF[i][k],WF[k][j]));
				}
			}
		}
		
		for(int j=0;j<N;j++){
			for(int i=0;i<N;i++){
				if(WF[i][j]<A[j])WF[i][j]=0;
			}
		}
		
		
		long mod=(long)1e9+7;
		long[][] nCr=new long[1001][];
		for(int i=0;i<=1000;i++)nCr[i]=new long[1001];
		nCr[0][0]=1;
		for(int i=1;i<=1000;i++){
			for(int j=0;j<=i;j++){
				nCr[i][j]=j==0?1:nCr[i-1][j-1]+nCr[i-1][j];
				if(nCr[i][j]>=mod)nCr[i][j]-=mod;
			}
		}
		
		long[][] iPown=new long[1001][];
		for(int i=0;i<1001;i++){
			iPown[i]=new long[1001];
			iPown[i][0]=1;
			for(int j=1;j<=1000;j++){
				iPown[i][j]=iPown[i][j-1]*i;
				if(iPown[i][j-1]>=mod)iPown[i][j-1]%=mod;
			}
		}
		
		
		long ans=0;
		for(int ii=0;ii<N;ii++){
			for(int jj=0;jj<N;jj++){
				if(WF[ii][jj]==0)continue;
				//A[i] -> A[j] surj:
				// n->k surj:Σ(-1)^{k-i}*kCi*i^n, i=1 to k
				int n=A[ii];
				int k=A[jj];
				long surj=0;
				for(int i=1;i<=k;i++){
					long term=nCr[k][i]*iPown[i][n];
					if(term>=mod)term%=mod;
					if((k-i)%2==0)surj+=term;
					if((k-i)%2!=0)surj+=mod-term;
					if(surj>=mod)surj%=mod;
				}
				ans+=surj;
				if(ans>=mod)ans%=mod;
			}
		}
		Console.WriteLine(ans);
}		
	}
	
	
	
	
	
	int N,M;
	int[] A;
	bool[,] Mp;
	public Sol(){
		var d=ria();
		N=d[0];M=d[1];
		A=ria();
		Mp=new bool[N,N];
		for(int i=0;i<M;i++){
			d=ria();
			Mp[d[0]-1,d[1]-1]=true;
		}
	}




	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