結果
| 問題 |
No.329 全射
|
| コンテスト | |
| ユーザー |
tjake
|
| 提出日時 | 2015-12-22 02:54:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,578 bytes |
| コンパイル時間 | 653 ms |
| コンパイル使用メモリ | 75,752 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-09-18 18:30:16 |
| 合計ジャッジ時間 | 48,063 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 TLE * 13 |
ソースコード
#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-9
typedef 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 1000000007
ll n, m;
ll w[N];
ll e[N][N];
ll memo[W][W];
ll c[W][W];
ll fact[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 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) {
if(e[i][k] != INF && e[k][j] != INF) {
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;
}
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;
}
tjake