結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 751 ms
28,000 KB
testcase_01 AC 748 ms
28,000 KB
testcase_02 AC 746 ms
28,000 KB
testcase_03 AC 753 ms
28,000 KB
testcase_04 AC 752 ms
28,000 KB
testcase_05 AC 749 ms
28,000 KB
testcase_06 AC 751 ms
28,000 KB
testcase_07 AC 749 ms
28,000 KB
testcase_08 AC 747 ms
28,000 KB
testcase_09 AC 749 ms
28,000 KB
testcase_10 AC 746 ms
28,000 KB
testcase_11 AC 748 ms
28,000 KB
testcase_12 AC 745 ms
28,000 KB
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 AC 749 ms
28,000 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
	
	for(i=1;i<=1000;i++) {
		for(x=1;x<=i;x++) {
			dp[i][x]=fact[x][i];
			for(y=1;y<x;y++) {
				//dp[i][x] -= C_[x][y] * dp[i][y] % mo;
				dp[i][x] -= mulmod(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]=W[i], assert(W[i]<=500);
	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