結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,516 KB
testcase_01 AC 38 ms
53,516 KB
testcase_02 AC 38 ms
53,516 KB
testcase_03 AC 390 ms
84,416 KB
testcase_04 AC 37 ms
53,516 KB
testcase_05 AC 37 ms
53,516 KB
testcase_06 AC 78 ms
74,852 KB
testcase_07 AC 52 ms
62,148 KB
testcase_08 AC 91 ms
76,156 KB
testcase_09 AC 55 ms
59,884 KB
testcase_10 AC 75 ms
72,420 KB
testcase_11 AC 74 ms
72,408 KB
testcase_12 AC 46 ms
59,652 KB
testcase_13 AC 52 ms
67,848 KB
testcase_14 AC 385 ms
84,412 KB
testcase_15 AC 414 ms
84,560 KB
testcase_16 AC 395 ms
84,564 KB
testcase_17 AC 106 ms
79,656 KB
testcase_18 AC 111 ms
77,844 KB
testcase_19 AC 108 ms
79,624 KB
testcase_20 AC 85 ms
73,260 KB
testcase_21 AC 95 ms
76,264 KB
testcase_22 AC 77 ms
70,660 KB
testcase_23 AC 102 ms
77,852 KB
testcase_24 AC 105 ms
79,672 KB
testcase_25 AC 60 ms
72,408 KB
testcase_26 AC 59 ms
72,408 KB
testcase_27 AC 58 ms
64,224 KB
testcase_28 AC 48 ms
68,136 KB
testcase_29 AC 92 ms
76,012 KB
testcase_30 AC 99 ms
79,616 KB
testcase_31 AC 94 ms
76,272 KB
testcase_32 AC 63 ms
72,408 KB
testcase_33 AC 54 ms
62,148 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]

p1 = p2 = p3 = 1
for i in range(t + 1, n + 1):
    if(i == n):
        p3 = p1
    p1 *= i
    if(p1 < MOD):
        continue
    p1 %= MOD
p2 = p3 * t % MOD if(t != n) else 1

ans = p1 * calc_dp((1 << t) - 1) % MOD
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 -= p2 * calc_dp((1 << t) - 1 - (1 << id)) % MOD
    else:
        ans -= p3 * calc_dp((1 << t) - 1) % MOD
    ans %= MOD

print(ans)
0