結果

問題 No.329 全射
ユーザー 👑 kmjpkmjp
提出日時 2015-12-22 01:04:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 162,288 KB
実行使用メモリ 12,428 KB
最終ジャッジ日時 2023-10-18 22:20:23
合計ジャッジ時間 3,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
12,192 KB
testcase_01 AC 9 ms
12,196 KB
testcase_02 AC 9 ms
12,196 KB
testcase_03 AC 9 ms
12,192 KB
testcase_04 AC 9 ms
12,196 KB
testcase_05 AC 9 ms
12,196 KB
testcase_06 AC 9 ms
12,196 KB
testcase_07 AC 9 ms
12,196 KB
testcase_08 AC 9 ms
12,196 KB
testcase_09 AC 9 ms
12,196 KB
testcase_10 AC 8 ms
12,192 KB
testcase_11 AC 9 ms
12,196 KB
testcase_12 AC 9 ms
12,196 KB
testcase_13 AC 29 ms
12,420 KB
testcase_14 AC 20 ms
12,384 KB
testcase_15 AC 19 ms
12,372 KB
testcase_16 AC 21 ms
12,372 KB
testcase_17 AC 23 ms
12,400 KB
testcase_18 AC 27 ms
12,408 KB
testcase_19 AC 31 ms
12,428 KB
testcase_20 AC 27 ms
12,412 KB
testcase_21 AC 24 ms
12,396 KB
testcase_22 AC 29 ms
12,428 KB
testcase_23 AC 13 ms
12,316 KB
testcase_24 AC 12 ms
12,312 KB
testcase_25 AC 17 ms
12,364 KB
testcase_26 AC 13 ms
12,332 KB
testcase_27 AC 10 ms
12,256 KB
testcase_28 AC 9 ms
12,212 KB
testcase_29 AC 10 ms
12,244 KB
testcase_30 AC 9 ms
12,232 KB
testcase_31 AC 9 ms
12,192 KB
testcase_32 AC 10 ms
12,248 KB
testcase_33 AC 18 ms
12,392 KB
testcase_34 AC 17 ms
12,380 KB
testcase_35 AC 21 ms
12,408 KB
testcase_36 AC 19 ms
12,396 KB
testcase_37 AC 17 ms
12,380 KB
testcase_38 AC 18 ms
12,392 KB
testcase_39 AC 19 ms
12,392 KB
testcase_40 AC 22 ms
12,412 KB
testcase_41 AC 17 ms
12,384 KB
testcase_42 AC 22 ms
12,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int W[300];
int mat[300][300];
ll mo=1000000007;

const int CN=1201;
ll C[CN][CN];

ll dp[1010][1010];
ll fact[1010];

void solve() {
	int i,j,k,l,r,x,y,z; string s;
	
	fact[0]=dp[0][0]=1;
	for(i=1;i<=1000;i++) {
		fact[i]=fact[i-1]*i%mo;
		dp[i][1]=1;
		for(j=2;j<=i;j++) dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]*j)%mo;
	}
	
	cin>>N>>M;
	FOR(i,N) cin>>W[i], mat[i][i]=W[i];
	FOR(i,M) {
		cin>>x>>y, x--, y--;
		mat[x][y]=min(W[x],W[y]);
	}
	
	FOR(z,N) FOR(x,N) FOR(y,N) mat[x][y] = max(mat[x][y], min(mat[x][z],mat[z][y]));
	
	ll ret=0;
	FOR(x,N) FOR(y,N) if(mat[x][y]>=W[y]) ret +=(dp[W[x]][W[y]] * fact[W[y]])%mo;
	
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0