結果

問題 No.329 全射
ユーザー 👑 kmjpkmjp
提出日時 2015-12-22 00:51:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 162,700 KB
実行使用メモリ 27,716 KB
最終ジャッジ日時 2023-10-18 22:18:26
合計ジャッジ時間 8,484 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
21,532 KB
testcase_01 AC 28 ms
21,536 KB
testcase_02 AC 28 ms
21,544 KB
testcase_03 AC 28 ms
21,532 KB
testcase_04 AC 28 ms
21,540 KB
testcase_05 AC 28 ms
21,532 KB
testcase_06 AC 29 ms
21,540 KB
testcase_07 AC 28 ms
21,532 KB
testcase_08 AC 28 ms
21,536 KB
testcase_09 AC 28 ms
21,540 KB
testcase_10 AC 28 ms
21,532 KB
testcase_11 AC 28 ms
21,536 KB
testcase_12 AC 28 ms
21,536 KB
testcase_13 AC 385 ms
23,580 KB
testcase_14 AC 325 ms
23,580 KB
testcase_15 AC 307 ms
23,580 KB
testcase_16 AC 311 ms
23,580 KB
testcase_17 AC 350 ms
23,580 KB
testcase_18 AC 371 ms
23,580 KB
testcase_19 AC 408 ms
23,580 KB
testcase_20 AC 376 ms
23,580 KB
testcase_21 AC 342 ms
23,580 KB
testcase_22 AC 402 ms
23,580 KB
testcase_23 AC 71 ms
27,716 KB
testcase_24 AC 73 ms
27,716 KB
testcase_25 AC 102 ms
27,716 KB
testcase_26 AC 91 ms
27,716 KB
testcase_27 AC 50 ms
27,712 KB
testcase_28 AC 36 ms
27,680 KB
testcase_29 AC 46 ms
27,708 KB
testcase_30 AC 44 ms
27,712 KB
testcase_31 AC 29 ms
23,576 KB
testcase_32 AC 44 ms
27,708 KB
testcase_33 AC 112 ms
27,716 KB
testcase_34 AC 92 ms
27,716 KB
testcase_35 AC 121 ms
27,716 KB
testcase_36 AC 117 ms
27,716 KB
testcase_37 AC 105 ms
27,716 KB
testcase_38 AC 106 ms
27,716 KB
testcase_39 AC 106 ms
27,716 KB
testcase_40 AC 117 ms
27,716 KB
testcase_41 AC 100 ms
27,716 KB
testcase_42 AC 135 ms
27,716 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 I[40404],J[40404];
ll mo=1000000007;
int mat[300][300];

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

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

inline int mulmod(int a,int b,int mo) {
	int d,r;
	if(a==0 || b==0) return 0;
	if(a==1 || b==1) return max(a,b);
	__asm__("mull %4;"
	        "divl %2"
		: "=d" (r), "=a" (d)
		: "r" (mo), "a" (a), "d" (b));
	return r;
}

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,1010) {
		fact[i][0]=1;
		FOR(j,1001) fact[i][j+1]=fact[i][j]*i%mo;
	}
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>W[i], mat[i][i]=W[i];
		z=W[i];
		
		for(x=1;x<=z;x++) {
			dp[z][x]=fact[x][z];
			for(y=1;y<x;y++) {
				dp[z][x] -= mulmod(C_[x][y],dp[z][y],mo);
				if(dp[z][x]<0) dp[z][x] += mo;
			}
		}
	}
	FOR(i,M) {
		cin>>I[i]>>J[i], I[i]--, J[i]--;
		mat[I[i]][J[i]]=min(W[I[i]],W[J[i]]);
	}
	
	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] && W[x]>=W[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