結果

問題 No.329 全射
ユーザー TawaraTawara
提出日時 2015-12-24 22:37:04
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 924 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 77,496 KB
実行使用メモリ 153,536 KB
最終ジャッジ日時 2023-10-19 02:55:55
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
81,860 KB
testcase_01 AC 86 ms
77,512 KB
testcase_02 AC 84 ms
77,512 KB
testcase_03 AC 84 ms
77,512 KB
testcase_04 AC 84 ms
77,512 KB
testcase_05 AC 81 ms
77,512 KB
testcase_06 AC 83 ms
77,512 KB
testcase_07 AC 85 ms
77,512 KB
testcase_08 AC 82 ms
77,512 KB
testcase_09 AC 86 ms
77,512 KB
testcase_10 AC 84 ms
77,512 KB
testcase_11 AC 85 ms
77,512 KB
testcase_12 AC 83 ms
77,512 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from collections import defaultdict as ddict
p = 10**9+7
N,M = map(int,raw_input().split())
w = map(int,raw_input().split())
w_max = max(w)
C = [[0]*(i+1) for i in xrange(w_max+1)]
C[0][0] = 1
for i in xrange(w_max):
	for j in xrange(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
E = [[] for i in xrange(N)]
for t in xrange(M):
	i,j = map(lambda x:int(x)-1,raw_input().split())
	E[i].append(j)
proj = set()
for s in xrange(N):
	visited = ddict(int)
	Q = []
	heappush(Q,(-w[s],s))
	while Q:
		w_min,h = heappop(Q)
		w_min *= -1
		if w_min <= visited[h]: continue
		visited[h] = w_min
		if w[s] >= w[h] and w[h] <= w_min:
			proj.add((s,h))
		w_min = min(w_min,w[h])
		for nxt in E[h]: heappush(Q,(-w_min,nxt))
ans = 0
for i,j in proj:
	wi = w[i]; wj = w[j]
	ans += sum(C[wj][k]*pow(wj-k,wi,p)*((-1)**(k%2)) for k in xrange(wj))
	ans %= p
print ans
0