結果

問題 No.329 全射
ユーザー ctyl_0ctyl_0
提出日時 2015-12-23 02:03:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 96,632 KB
実行使用メモリ 11,796 KB
最終ジャッジ日時 2023-10-18 23:26:21
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,548 KB
testcase_01 AC 10 ms
11,548 KB
testcase_02 AC 10 ms
11,548 KB
testcase_03 AC 9 ms
11,548 KB
testcase_04 AC 9 ms
11,548 KB
testcase_05 AC 9 ms
11,548 KB
testcase_06 AC 10 ms
11,548 KB
testcase_07 AC 9 ms
11,548 KB
testcase_08 AC 9 ms
11,548 KB
testcase_09 AC 9 ms
11,548 KB
testcase_10 AC 9 ms
11,548 KB
testcase_11 AC 9 ms
11,548 KB
testcase_12 AC 9 ms
11,548 KB
testcase_13 AC 24 ms
11,692 KB
testcase_14 AC 16 ms
11,680 KB
testcase_15 AC 18 ms
11,736 KB
testcase_16 AC 21 ms
11,640 KB
testcase_17 AC 20 ms
11,776 KB
testcase_18 AC 25 ms
11,680 KB
testcase_19 AC 25 ms
11,704 KB
testcase_20 AC 25 ms
11,688 KB
testcase_21 AC 22 ms
11,664 KB
testcase_22 AC 22 ms
11,796 KB
testcase_23 AC 14 ms
11,668 KB
testcase_24 AC 13 ms
11,656 KB
testcase_25 AC 17 ms
11,716 KB
testcase_26 AC 14 ms
11,652 KB
testcase_27 AC 10 ms
11,568 KB
testcase_28 AC 9 ms
11,548 KB
testcase_29 AC 10 ms
11,560 KB
testcase_30 AC 10 ms
11,556 KB
testcase_31 AC 10 ms
11,548 KB
testcase_32 AC 10 ms
11,564 KB
testcase_33 AC 15 ms
11,664 KB
testcase_34 AC 14 ms
11,648 KB
testcase_35 AC 16 ms
11,680 KB
testcase_36 AC 16 ms
11,668 KB
testcase_37 AC 13 ms
11,648 KB
testcase_38 AC 14 ms
11,660 KB
testcase_39 AC 15 ms
11,664 KB
testcase_40 AC 17 ms
11,688 KB
testcase_41 AC 14 ms
11,652 KB
testcase_42 AC 17 ms
11,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int main() {
    cin.tie(0);
    // source code
    // calc strling number
    vector<vector<ll>> S(1001, vector<ll>(1001, 0));
    
    repd(i, 1, 1001) S[i][1] = 1;
    repd(i, 2, 1001) repd(j, 2, i + 1){
        S[i][j] = j * (S[i - 1][j] + S[i - 1][j - 1]);
        S[i][j] %= mod;
    }
    
    
    int N, M;
    cin >> N >> M;
    
    vector<vector<int>> E(N, vector<int>(N, 0));
    vector<int> W(N);
    rep(i, N) cin >> W[i], E[i][i] = W[i];
    vector<pair<int, int>> A(M);
    rep(i, M) cin >> A[i].first >> A[i].second, E[A[i].first - 1][A[i].second - 1] = W[A[i].second - 1];
    
    rep(k, N) rep(i, N) rep(j, N){
        E[i][j] = max(E[i][j], min(E[i][k], E[k][j]));
    }
    
    ll ret = 0;
    rep(i, N) rep(j, N){
        if (E[i][j] >= W[j]) {
            ret += S[W[i]][W[j]];
            ret %= mod;
        }
    }
    
    output(ret, 0);
    
    return 0;
}
0