結果

問題 No.329 全射
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-18 18:17:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,414 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 106,592 KB
実行使用メモリ 13,164 KB
最終ジャッジ日時 2023-09-03 22:21:35
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,652 KB
testcase_01 AC 7 ms
8,500 KB
testcase_02 AC 8 ms
10,084 KB
testcase_03 AC 7 ms
8,532 KB
testcase_04 AC 8 ms
8,292 KB
testcase_05 AC 8 ms
11,544 KB
testcase_06 AC 8 ms
9,004 KB
testcase_07 AC 8 ms
11,080 KB
testcase_08 AC 7 ms
8,780 KB
testcase_09 AC 7 ms
8,488 KB
testcase_10 AC 7 ms
8,200 KB
testcase_11 AC 6 ms
8,244 KB
testcase_12 AC 7 ms
8,276 KB
testcase_13 AC 41 ms
12,884 KB
testcase_14 AC 23 ms
9,252 KB
testcase_15 AC 26 ms
11,624 KB
testcase_16 AC 31 ms
13,164 KB
testcase_17 AC 31 ms
13,072 KB
testcase_18 AC 40 ms
12,632 KB
testcase_19 AC 44 ms
12,596 KB
testcase_20 AC 39 ms
12,644 KB
testcase_21 AC 34 ms
12,012 KB
testcase_22 AC 39 ms
12,064 KB
testcase_23 AC 17 ms
11,580 KB
testcase_24 AC 16 ms
11,920 KB
testcase_25 AC 23 ms
12,588 KB
testcase_26 AC 16 ms
9,784 KB
testcase_27 AC 9 ms
9,540 KB
testcase_28 AC 7 ms
8,980 KB
testcase_29 AC 8 ms
8,736 KB
testcase_30 AC 8 ms
8,412 KB
testcase_31 AC 7 ms
8,456 KB
testcase_32 AC 8 ms
8,736 KB
testcase_33 AC 16 ms
8,468 KB
testcase_34 AC 16 ms
10,288 KB
testcase_35 AC 20 ms
11,532 KB
testcase_36 AC 18 ms
9,284 KB
testcase_37 AC 14 ms
8,916 KB
testcase_38 AC 17 ms
10,012 KB
testcase_39 AC 16 ms
8,736 KB
testcase_40 AC 20 ms
8,740 KB
testcase_41 AC 14 ms
8,500 KB
testcase_42 AC 21 ms
10,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable MO = 10L^^9 + 7;
immutable LIM = 1010;

long[] fac;
long[][] S;

void prepare() {
  fac = new long[LIM];
  fac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = (fac[i - 1] * i) % MO;
  }
  S = new long[][LIM];
  foreach (i; 0 .. LIM) {
    S[i] = new long[i + 1];
    S[i][0] = 0;
    S[i][i] = 1;
    foreach (j; 1 .. i) {
      S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j]) % MO;
    }
  }
}

int N, M;
int[] W;
int[] A, B;

void main() {
  prepare();
  
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      W = new int[N];
      foreach (u; 0 .. N) {
        W[u] = readInt();
      }
      A = new int[M];
      B = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
      }
      
      auto d = new int[][](N, N);
      foreach (u; 0 .. N) {
        d[u][u] = W[u];
      }
      foreach (i; 0 .. M) {
        chmax(d[A[i]][B[i]], min(W[A[i]], W[B[i]]));
      }
      foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) {
        chmax(d[u][v], min(d[u][w], d[w][v]));
      }
      debug {
        writeln("d = ", d);
      }
      
      long ans;
      foreach (u; 0 .. N) foreach (v; 0 .. N) {
        if (d[u][v] == W[v]) {
          (ans += fac[W[v]] * S[W[u]][W[v]]) %= MO;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0