結果

問題 No.329 全射
ユーザー sugim48sugim48
提出日時 2015-12-22 03:03:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 94,768 KB
実行使用メモリ 7,840 KB
最終ジャッジ日時 2023-10-18 22:31:06
合計ジャッジ時間 3,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,632 KB
testcase_01 AC 16 ms
7,632 KB
testcase_02 AC 16 ms
7,632 KB
testcase_03 AC 16 ms
7,632 KB
testcase_04 AC 16 ms
7,632 KB
testcase_05 AC 16 ms
7,632 KB
testcase_06 AC 16 ms
7,632 KB
testcase_07 AC 16 ms
7,632 KB
testcase_08 AC 16 ms
7,632 KB
testcase_09 AC 16 ms
7,632 KB
testcase_10 AC 16 ms
7,632 KB
testcase_11 AC 16 ms
7,632 KB
testcase_12 AC 16 ms
7,632 KB
testcase_13 AC 34 ms
7,764 KB
testcase_14 AC 20 ms
7,680 KB
testcase_15 AC 26 ms
7,740 KB
testcase_16 AC 34 ms
7,836 KB
testcase_17 AC 29 ms
7,748 KB
testcase_18 AC 38 ms
7,840 KB
testcase_19 AC 35 ms
7,768 KB
testcase_20 AC 35 ms
7,760 KB
testcase_21 AC 31 ms
7,748 KB
testcase_22 AC 28 ms
7,716 KB
testcase_23 AC 23 ms
7,704 KB
testcase_24 AC 22 ms
7,704 KB
testcase_25 AC 26 ms
7,732 KB
testcase_26 AC 21 ms
7,684 KB
testcase_27 AC 17 ms
7,648 KB
testcase_28 AC 16 ms
7,632 KB
testcase_29 AC 17 ms
7,640 KB
testcase_30 AC 16 ms
7,636 KB
testcase_31 AC 16 ms
7,632 KB
testcase_32 AC 17 ms
7,640 KB
testcase_33 AC 16 ms
7,636 KB
testcase_34 AC 16 ms
7,636 KB
testcase_35 AC 16 ms
7,636 KB
testcase_36 AC 16 ms
7,636 KB
testcase_37 AC 16 ms
7,636 KB
testcase_38 AC 17 ms
7,636 KB
testcase_39 AC 17 ms
7,636 KB
testcase_40 AC 17 ms
7,636 KB
testcase_41 AC 16 ms
7,636 KB
testcase_42 AC 16 ms
7,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void dfs(int u, int x, vector<int>& a, vector<vector<int> >& G, vector<bool>& vis) {
	vis[u] = true;
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (!vis[v] && a[v] >= x)
			dfs(v, x, a, G, vis);
	}
}

int main() {
	vector<int> fact(1001);
	fact[0] = 1;
	for (int i = 1; i <= 1000; i++)
		fact[i] = (ll)fact[i - 1] * i % MOD;
	vector<vector<int> > dp(1001, vector<int>(1001));
	dp[0][0] = 1;
	for (int i = 1; i <= 1000; i++)
		for (int j = 0; j < i; j++) {
			dp[i][j] = (dp[i][j] + (ll)j * dp[i - 1][j]) % MOD;
			dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % MOD;
		}
	int N, M; cin >> N >> M;
	vector<int> a(N);
	for (int u = 0; u < N; u++)
		cin >> a[u];
	vector<i_i> au(N);
	for (int u = 0; u < N; u++)
		au[u] = i_i(a[u], u);
	sort(au.begin(), au.end());
	vector<vector<int> > G(N);
	while (M--) {
		int u, v; cin >> u >> v;
		u--; v--;
		G[v].push_back(u);
	}
	int sum = 0;
	for (int u = 0; u < N; u++) {
		vector<bool> vis(N);
		dfs(u, a[u], a, G, vis);
		for (int v = 0; v < N; v++)
			if (vis[v])
				sum = (sum + (ll)fact[a[u]] * dp[a[v]][a[u]]) % MOD;
	}
	cout << sum << endl;
}
0