結果

問題 No.329 全射
ユーザー btkbtk
提出日時 2015-12-22 20:10:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 1,257 ms
コンパイル使用メモリ 161,328 KB
実行使用メモリ 11,840 KB
最終ジャッジ日時 2023-10-18 22:44:27
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int z[300];
int w[300];
int d[300][300];
const LL MOD=1e9+7;

LL dp[1001][1001];
inline void zensha(){
    fill((LL*)dp,(LL*)dp+1001*1001,0);
    for(int n=1;n<1001;n++){
        dp[n][1]=1;
        for(int m=2;m<=n;m++)
            dp[n][m]=m*(dp[n-1][m]+dp[n-1][m-1])%MOD;
    }
}
int main() {
    fill((int*)d,(int*)d+300*300,0);
    zensha();
    int N,M;
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>w[i];
        d[i][i]=w[i];
    }
    for(int i=0;i<M;i++){
        int from,to;
        cin>>from>>to;
        d[from-1][to-1]=min(w[from-1],w[to-1]);
    }
    for(int k = 0; k < N; k++)
    for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
    d[i][j]=max(d[i][j],min(d[i][k],d[k][j]));
    LL res=0;
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++){
        if(d[i][j]==w[j]){
            res+=dp[w[i]][d[i][j]];
            res%=MOD;
        }
    }
    cout<<res<<endl;
    return 0;
}
0