結果

問題 No.329 全射
ユーザー motimoti
提出日時 2015-12-27 19:28:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,371 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 108,076 KB
実行使用メモリ 12,536 KB
最終ジャッジ日時 2023-10-19 11:22:26
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,336 KB
testcase_01 AC 5 ms
12,336 KB
testcase_02 AC 6 ms
12,336 KB
testcase_03 AC 5 ms
12,336 KB
testcase_04 AC 6 ms
12,336 KB
testcase_05 AC 5 ms
12,336 KB
testcase_06 AC 5 ms
12,336 KB
testcase_07 AC 5 ms
12,336 KB
testcase_08 AC 5 ms
12,336 KB
testcase_09 AC 5 ms
12,336 KB
testcase_10 AC 6 ms
12,336 KB
testcase_11 AC 6 ms
12,336 KB
testcase_12 AC 5 ms
12,336 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 5 ms
12,336 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

constexpr int inf = 1<<29;

int const MOD = 1e9+7;
typedef long long ll;

namespace math { namespace combination {  // experimental

#define COMBINATION_MAX 1010

namespace memorized { namespace stirling_number {
  enum { max_value = COMBINATION_MAX };
  bool __computed = false; inline bool computed() {if(__computed) { return true; } else { __computed = true; return false; }}
  ll dp[max_value][max_value];
}}

ll stirling_number(int N, int K) {
  using memorized::stirling_number::dp;
  if(memorized::stirling_number::computed()) { return dp[N][K]; }

  // Make stirling numbers
  using memorized::stirling_number::max_value;

  REP(i, 1, max_value) {  // undefined when i = 0
    dp[i][1] = dp[i][i] = 1;
    REP(j, 2, i) {
      dp[i][j] = dp[i-1][j-1] + j * dp[i-1][j];
    }
  }

  return dp[N][K];
}

}}

int N, M;
vector<int> g[222];
ll fact[1010];
ll dp[300][300];

int main() {

  cin >> N >> M;

  vector<ll> ws(N);
  rep(i, N) {
    cin >> ws[i];
  }

  rep(i, M) {
    int a, b; cin >> a >> b; a--, b--;
    g[a].push_back(b);
  }

  zero(dp);
  rep(i, N) {
    dp[i][i] = ws[i];
    rep(j, g[i].size()) {
      int tar = g[i][j];
      dp[i][tar] = min(dp[i][i], ws[tar]);
    }
  }

  rep(k, N) rep(i, N) rep(j, N) {
    maximize(dp[i][j], min(dp[i][k], dp[k][j]));
  }

  fact[0] = 1;
  rep(i, 1000) fact[i+1] = fact[i] * (i+1) % MOD;

  // 異なるN個を異なるK個に振り分ける方法の数(全射の数) := S(N, K) * K!
  using math::combination::stirling_number;

  ll ans = 0;

  rep(i, N) rep(j, N) {
    if(dp[i][j] < ws[j]) { continue; }
    ans += stirling_number(ws[i], ws[j]) * fact[ws[j]] % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
0