結果
問題 |
No.329 全射
|
ユーザー |
![]() |
提出日時 | 2015-12-25 14:41:35 |
言語 | PyPy2 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 906 bytes |
コンパイル時間 | 905 ms |
コンパイル使用メモリ | 77,188 KB |
実行使用メモリ | 153,332 KB |
最終ジャッジ日時 | 2024-09-18 23:47:54 |
合計ジャッジ時間 | 5,511 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 1 -- * 29 |
ソースコード
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) F = ddict(int) for s in xrange(N): V = ddict(int) Q = [] heappush(Q,(-w[s],s)) while Q: w_min,h = heappop(Q) w_min *= -1 if w_min <= V[h]: continue V[h] = w_min if w[s] >= w[h] and w[h] <= w_min: F[(w[s],w[h])] += 1 w_min = min(w_min,w[h]) for nxt in E[h]: heappush(Q,(-w_min,nxt)) ans = 0 for (wi,wj),v in F.iteritems(): ans += v * sum(C[wj][k]*pow(wj-k,wi,p)*((-1)**(k%2)) for k in xrange(wj)) ans %= p print ans