結果

問題 No.329 全射
ユーザー tjaketjake
提出日時 2015-12-22 04:16:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 75,132 KB
実行使用メモリ 11,884 KB
最終ジャッジ日時 2023-10-18 22:31:41
合計ジャッジ時間 2,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,532 KB
testcase_01 AC 5 ms
11,532 KB
testcase_02 AC 4 ms
11,536 KB
testcase_03 AC 4 ms
11,532 KB
testcase_04 AC 4 ms
11,532 KB
testcase_05 AC 4 ms
11,532 KB
testcase_06 AC 5 ms
11,532 KB
testcase_07 AC 5 ms
11,532 KB
testcase_08 AC 4 ms
11,532 KB
testcase_09 AC 5 ms
11,532 KB
testcase_10 AC 4 ms
11,532 KB
testcase_11 AC 4 ms
11,532 KB
testcase_12 AC 4 ms
11,532 KB
testcase_13 AC 24 ms
11,868 KB
testcase_14 AC 15 ms
11,820 KB
testcase_15 AC 16 ms
11,804 KB
testcase_16 AC 20 ms
11,804 KB
testcase_17 AC 19 ms
11,844 KB
testcase_18 AC 24 ms
11,852 KB
testcase_19 AC 25 ms
11,884 KB
testcase_20 AC 24 ms
11,864 KB
testcase_21 AC 21 ms
11,836 KB
testcase_22 AC 21 ms
11,884 KB
testcase_23 AC 19 ms
11,712 KB
testcase_24 AC 18 ms
11,704 KB
testcase_25 AC 23 ms
11,772 KB
testcase_26 AC 19 ms
11,728 KB
testcase_27 AC 15 ms
11,640 KB
testcase_28 AC 12 ms
11,572 KB
testcase_29 AC 15 ms
11,624 KB
testcase_30 AC 11 ms
11,604 KB
testcase_31 AC 4 ms
11,548 KB
testcase_32 AC 13 ms
11,632 KB
testcase_33 AC 18 ms
11,828 KB
testcase_34 AC 18 ms
11,812 KB
testcase_35 AC 20 ms
11,848 KB
testcase_36 AC 21 ms
11,840 KB
testcase_37 AC 18 ms
11,816 KB
testcase_38 AC 18 ms
11,812 KB
testcase_39 AC 18 ms
11,836 KB
testcase_40 AC 20 ms
11,856 KB
testcase_41 AC 17 ms
11,820 KB
testcase_42 AC 21 ms
11,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 fcnt(ll n, ll k) {
  if(k==1) return 1;
  if(n < k) return 0;
  if(memo[n][k]!=-1) return memo[n][k];
  return memo[n][k] = (k*(fcnt(n-1, k-1)+fcnt(n-1, k))) % MOD;
}

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] = -1;

  ll ans = 0;
  rep(i, n) {
    rep(j, n) {
      if(i==j) {
        ans = (ans + fcnt(w[i], w[i])) % MOD;
      } else if(w[i] >= w[j] && e[i][j]>=w[j]) {
        ans = (ans + fcnt(w[i], w[j])) % MOD;
      }
    }
  }
  cout << ans << endl;

  return 0;
}
0