結果

問題 No.329 全射
ユーザー 👑 kmjpkmjp
提出日時 2015-12-22 00:34:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,485 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 162,380 KB
実行使用メモリ 17,996 KB
最終ジャッジ日時 2023-10-18 22:13:26
合計ジャッジ時間 12,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 230 ms
17,968 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 229 ms
17,968 KB
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 -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

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 I[40404],J[40404];
ll mo=1000000007;
int mat[300][300];

static const int N_=1020;
static ll C_[N_][N_];

ll dp[1010][1010];

void solve() {
	int i,j,k,l,r,x,y,z; string s;
	
	
	FOR(i,N_) C_[i][0]=C_[i][i]=1;
	for(i=1;i<N_;i++) for(j=1;j<i;j++) C_[i][j]=(C_[i-1][j-1]+C_[i-1][j])%mo;
	
	for(i=1;i<=500;i++) {
		ll fact = i;
		dp[i][1]=1;
		for(x=2;x<=i;x++) {
			fact = fact*i%mo;
			dp[i][x]=fact;
			for(y=1;y<x;y++) {
				dp[i][x] -= C_[x][y] * dp[i][y] % mo;
				if(dp[i][x]<0) dp[i][x] += mo;
			}
		}
	}
	
	
	cin>>N>>M;
	FOR(i,N) cin>>W[i], mat[i][i]=1;
	FOR(i,M) {
		cin>>I[i]>>J[i], I[i]--, J[i]--;
		if(W[I[i]]>=W[J[i]]) mat[I[i]][J[i]]=1;
	}
	
	FOR(z,N) FOR(z,N) FOR(y,N) mat[x][y] |= mat[x][z] && mat[z][y];
	ll ret=0;
	FOR(x,N) FOR(y,N) if(mat[x][y]) ret +=dp[W[x]][W[y]];
	
	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