結果

問題 No.329 全射
ユーザー TawaraTawara
提出日時 2015-12-25 13:27:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,050 ms / 2,000 ms
コード長 1,640 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 89,628 KB
実行使用メモリ 18,832 KB
最終ジャッジ日時 2023-10-19 03:34:04
合計ジャッジ時間 11,994 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
18,500 KB
testcase_01 AC 13 ms
18,504 KB
testcase_02 AC 13 ms
18,504 KB
testcase_03 AC 13 ms
18,500 KB
testcase_04 AC 13 ms
18,504 KB
testcase_05 AC 14 ms
18,504 KB
testcase_06 AC 13 ms
18,504 KB
testcase_07 AC 14 ms
18,504 KB
testcase_08 AC 13 ms
18,500 KB
testcase_09 AC 13 ms
18,504 KB
testcase_10 AC 13 ms
18,500 KB
testcase_11 AC 13 ms
18,504 KB
testcase_12 AC 13 ms
18,500 KB
testcase_13 AC 967 ms
18,752 KB
testcase_14 AC 328 ms
18,600 KB
testcase_15 AC 524 ms
18,732 KB
testcase_16 AC 806 ms
18,828 KB
testcase_17 AC 678 ms
18,744 KB
testcase_18 AC 1,050 ms
18,832 KB
testcase_19 AC 1,014 ms
18,752 KB
testcase_20 AC 978 ms
18,748 KB
testcase_21 AC 786 ms
18,744 KB
testcase_22 AC 727 ms
18,708 KB
testcase_23 AC 195 ms
18,704 KB
testcase_24 AC 166 ms
18,696 KB
testcase_25 AC 301 ms
18,728 KB
testcase_26 AC 139 ms
18,660 KB
testcase_27 AC 28 ms
18,548 KB
testcase_28 AC 15 ms
18,504 KB
testcase_29 AC 22 ms
18,524 KB
testcase_30 AC 19 ms
18,524 KB
testcase_31 AC 14 ms
18,500 KB
testcase_32 AC 23 ms
18,524 KB
testcase_33 AC 14 ms
18,512 KB
testcase_34 AC 15 ms
18,512 KB
testcase_35 AC 16 ms
18,512 KB
testcase_36 AC 15 ms
18,512 KB
testcase_37 AC 15 ms
18,512 KB
testcase_38 AC 15 ms
18,512 KB
testcase_39 AC 15 ms
18,512 KB
testcase_40 AC 15 ms
18,512 KB
testcase_41 AC 15 ms
18,508 KB
testcase_42 AC 15 ms
18,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef long long LL;
typedef pair<int,int> PII;

#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)

#define P 1000000007

LL C[1001][1001],F[1001][1001];
int w[1000];

LL my_pow(LL b, LL e){
	LL ret = 1, prod = b;
	for (LL inc=e;inc>0;inc>>=1){
		if (inc&1){ret *= prod; ret %= P;}
		prod = prod * prod % P;
	}
	return ret;
}
LL calc(LL wi, LL wj){
	LL ret = 0;
	for(LL k = 0;k < wj; k++){
		ret += (k%2?-1:1)*((C[wj][k]*my_pow(wj-k,wi))%P);
		ret = (ret + P) % P;
	}
	return ret;
}
int main(){
	int N,M,x,y,h,w_min;
	LL ans = 0;
	VVI E;
	VI :: iterator it;
	PII tmp;
	map <int,int> V;
	priority_queue <PII, vector<PII> > Q;
	C[0][0] = 1;
	rep(i,1000) rep(j,i+1){
		C[i+1][j]+=C[i][j]; C[i+1][j]%=P;
		C[i+1][j+1]+=C[i][j]; C[i+1][j+1]%=P;
	}
	range(i,1,1001) range(j,1,i+1) F[i][j] = 0;
	cin >> N >> M;
	E.resize(N);
	rep(i,N) cin >> w[i];
	rep(i,M){cin >> x >> y;E[--x].push_back(--y);}
	rep(s,N){
		V.clear();
		Q.push(PII(w[s],s));
		while (Q.size()>0){
			tmp = Q.top(); Q.pop();
			w_min = tmp.first; h = tmp.second;
			if (w_min <= V[h]) continue;
			V[h] = w_min;
			if(w[s] >= w[h] && w[h] <= w_min) F[w[s]][w[h]] += 1;
			w_min = min(w_min,w[h]);
			for (it=E[h].begin(); it!=E[h].end(); it++) Q.push(PII(w_min,*it));
		}
	}
	for(LL i=1; i < 1001; i++){
		for(LL j = 1;j < i+1; j++){
			if (F[i][j] > 0){
				ans += F[i][j]*calc(i,j) % P;
				ans %= P;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0