結果

問題 No.2522 Fall in love, Girls!
ユーザー MasKoaTSMasKoaTS
提出日時 2023-08-26 23:56:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 84,596 KB
最終ジャッジ日時 2023-10-27 20:50:20
合計ジャッジ時間 4,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,556 KB
testcase_01 AC 35 ms
53,556 KB
testcase_02 AC 35 ms
53,556 KB
testcase_03 AC 354 ms
84,396 KB
testcase_04 AC 35 ms
53,556 KB
testcase_05 AC 35 ms
53,556 KB
testcase_06 AC 76 ms
76,312 KB
testcase_07 AC 51 ms
62,208 KB
testcase_08 AC 88 ms
76,128 KB
testcase_09 AC 64 ms
60,068 KB
testcase_10 AC 82 ms
72,480 KB
testcase_11 AC 82 ms
72,468 KB
testcase_12 AC 57 ms
59,396 KB
testcase_13 AC 59 ms
67,592 KB
testcase_14 AC 367 ms
84,396 KB
testcase_15 AC 393 ms
84,596 KB
testcase_16 AC 388 ms
84,596 KB
testcase_17 AC 112 ms
79,716 KB
testcase_18 AC 117 ms
77,904 KB
testcase_19 AC 113 ms
79,684 KB
testcase_20 AC 92 ms
73,320 KB
testcase_21 AC 102 ms
76,352 KB
testcase_22 AC 86 ms
71,236 KB
testcase_23 AC 111 ms
77,916 KB
testcase_24 AC 108 ms
79,808 KB
testcase_25 AC 69 ms
72,468 KB
testcase_26 AC 65 ms
72,468 KB
testcase_27 AC 61 ms
64,280 KB
testcase_28 AC 48 ms
70,368 KB
testcase_29 AC 96 ms
76,048 KB
testcase_30 AC 107 ms
79,792 KB
testcase_31 AC 96 ms
76,308 KB
testcase_32 AC 66 ms
72,468 KB
testcase_33 AC 62 ms
62,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
MOD = 998244353

n, m, _ = map(int, input().split())
edges = [[x - 1 for x in map(int, input().split())] for _ in [0] * _]

st = set([])
for edge in edges:
    st |= set(edge)
lis = list(st)
di = { x : i for i, x in enumerate(lis)}
t = len(lis)

graph = [[0] * t for _ in [0] * t]
for x, y in edges:
    graph[di[x]][di[y]] = 1

dp = [-1] * (1 << t)
dp[0] = 1
def calc_dp(s):
    global dp
    if(dp[s] == -1):
        dp[s] = 0
        for i in range(t):
            if not((s >> i) & 1):
                continue
            if all(i == j or not((s >> j) & 1) or graph[j][i] == 0 for j in range(t)):
                dp[s] += calc_dp(s - (1 << i))
        dp[s] %= MOD
    return dp[s]

def nPk(n, k):
    ret = 1
    for i in range(n, n - k, -1):
        ret *= i
        ret %= MOD
    return ret

ans = nPk(n, n - t) * calc_dp((1 << t) - 1) % MOD
p1 = nPk(n - 1, n - t)
p2 = nPk(n - 1, n - t - 1)
for i in range(m):
    if(i in st):
        id = di[i]
        if any(id != j and graph[j][id] == 1 for j in range(t)):
            continue
        ans -= p1 * calc_dp((1 << t) - 1 - (1 << id)) % MOD
    else:
        ans -= p2 * calc_dp((1 << t) - 1) % MOD
    ans %= MOD

print(ans)
0