結果

問題 No.2522 Fall in love, Girls!
ユーザー MasKoaTSMasKoaTS
提出日時 2023-08-27 00:19:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,209 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 84,468 KB
最終ジャッジ日時 2023-10-27 20:50:19
合計ジャッジ時間 4,899 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,608 KB
testcase_01 AC 30 ms
53,608 KB
testcase_02 AC 30 ms
53,608 KB
testcase_03 AC 313 ms
84,468 KB
testcase_04 AC 32 ms
53,608 KB
testcase_05 AC 32 ms
53,608 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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
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 -= nPk(N - 1, N - t) * calc_dp((1 << t) - 1 - (1 << id)) % MOD
    else:
        ans -= nPk(N - 1, N - t - 1) * calc_dp((1 << t) - 1) % MOD
    ans %= MOD

print(ans)
0