結果
| 問題 |
No.329 全射
|
| コンテスト | |
| ユーザー |
Tawara
|
| 提出日時 | 2015-12-25 13:04:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,219 ms / 2,000 ms |
| コード長 | 1,449 bytes |
| コンパイル時間 | 831 ms |
| コンパイル使用メモリ | 90,112 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-09-18 23:45:58 |
| 合計ジャッジ時間 | 12,587 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#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<LL,int> PLI;
#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];
LL 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;
LL w_min,ans = 0;
VVI E;
VI :: iterator it;
PLI tmp;
map <int,LL> V;
priority_queue <PLI, vector<PLI> > 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;
}
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(PLI(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){ans += calc(w[s],w[h]); ans %= P;}
w_min = min(w_min,w[h]);
for (it=E[h].begin(); it!=E[h].end(); it++) Q.push(PLI(w_min,*it));
}
}
cout << ans << endl;
return 0;
}
Tawara