結果
問題 | No.329 全射 |
ユーザー |
![]() |
提出日時 | 2015-12-22 03:00:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,606 ms / 2,000 ms |
コード長 | 2,808 bytes |
コンパイル時間 | 550 ms |
コンパイル使用メモリ | 75,960 KB |
実行使用メモリ | 19,492 KB |
最終ジャッジ日時 | 2024-09-18 18:31:20 |
合計ジャッジ時間 | 32,153 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include<iostream>#include<string>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>#include<functional>#include<cstdio>#include<cstdlib>#include<cmath>using namespace std;#define mind(a,b) (a>b?b:a)#define maxd(a,b) (a>b?a:b)#define absd(x) (x<0?-(x):x)#define pow2(x) ((x)*(x))#define rep(i,n) for(int i=0; i<n; ++i)#define repr(i,n) for(int i=n-1; i>=0; --i)#define repl(i,s,n) for(int i=s; i<=n; ++i)#define replr(i,s,n) for(int i=n; i>=s; --i)#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)#define repe(e,obj) for(auto e : obj)#define SP << " " <<#define COL << " : " <<#define COM << ", " <<#define ARR << " -> " <<#define PNT(STR) cout << STR << endl#define POS(X,Y) "(" << X << ", " << Y << ")"#define DEB(A) " (" << #A << ") " << A#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl#define ALL(V) (V).begin(), (V).end()#define INF 1000000007#define INFLL 10000000000000000007LL#define EPS 1e-9typedef unsigned int uint;typedef unsigned long ulong;typedef unsigned long long ull;typedef long long ll;typedef long double ld;typedef pair<int, int> P;//typedef pair<ll, ll> P;typedef pair<P, int> PI;typedef pair<int, P> IP;typedef pair<P, P> PP;typedef priority_queue<P, vector<P>, greater<P> > pvqueue;#define W 1003#define N 203#define MOD 1000000007ll n, m;ll w[N];ll e[N][N];ll memo[W][W];ll c[W][W];ll fact[W], rev[W];ll comb(ll n, ll k) {if(c[n][k]!=-1) return c[n][k];// if(n < 2*k) k = n-k;// if(n==k || k==0) return 1;// return c[n][k] = (comb(n-1, k-1) + comb(n-1, k)) % MOD;ll r = (rev[k]*rev[n-k]) % MOD;return c[n][k] = (fact[n] * r) % MOD;}ll fast_pow(ll x, ll n) {ll r = 1;while(n>0) {if(n&1) {r = (r * x) % MOD;}x = (x * x) % MOD;n >>= 1;}return r;}ll fcnt(ll wi, ll wj) {if(wi < wj) return 0;if(memo[wi][wj]!=-1) return memo[wi][wj];if(wj==1) return 1;ll r = 0;repl(i, 1, wi) {r = (r + (fcnt(wi-i, wj-1)*comb(wi, i))%MOD ) % MOD;}return memo[wi][wj] = r;}int main() {cin >> n >> m;rep(i, n) cin >> w[i];rep(i, m) {ll s, t;cin >> s >> t; --s; --t;e[s][t] = mind(w[s], w[t]);}rep(i, n) e[i][i] = 1;rep(k, n) rep(i, n) rep(j, n) {ll r = mind(e[i][k], e[k][j]);e[i][j] = maxd(e[i][j], r);}rep(i, W) rep(j, W) memo[i][j] = c[i][j] = -1;fact[0] = 1;rep(i, W-1) {fact[i+1] = ((i+1)*fact[i]) % MOD;rev[i+1] = fast_pow(fact[i+1], MOD-2);}ll ans = 0;rep(i, n) {rep(j, n) {if(i==j) {ans = (ans + fact[w[i]]) % MOD;} else if(w[i] >= w[j] && e[i][j]!=INF && e[i][j]>=w[j]) {ans = (ans + fcnt(w[i], w[j])) % MOD;}}}cout << ans << endl;return 0;}