結果
問題 | No.2522 Fall in love, Girls! |
ユーザー | MasKoaTS |
提出日時 | 2023-08-28 15:40:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 205 ms / 2,000 ms |
コード長 | 1,265 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 81,856 KB |
実行使用メモリ | 84,388 KB |
最終ジャッジ日時 | 2023-10-27 20:50:30 |
合計ジャッジ時間 | 3,555 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
53,556 KB |
testcase_01 | AC | 30 ms
53,556 KB |
testcase_02 | AC | 31 ms
53,556 KB |
testcase_03 | AC | 183 ms
84,200 KB |
testcase_04 | AC | 31 ms
53,556 KB |
testcase_05 | AC | 30 ms
53,556 KB |
testcase_06 | AC | 57 ms
68,572 KB |
testcase_07 | AC | 43 ms
62,212 KB |
testcase_08 | AC | 63 ms
72,688 KB |
testcase_09 | AC | 44 ms
59,384 KB |
testcase_10 | AC | 50 ms
67,860 KB |
testcase_11 | AC | 48 ms
67,580 KB |
testcase_12 | AC | 48 ms
60,056 KB |
testcase_13 | AC | 68 ms
72,552 KB |
testcase_14 | AC | 205 ms
84,388 KB |
testcase_15 | AC | 187 ms
84,040 KB |
testcase_16 | AC | 204 ms
84,388 KB |
testcase_17 | AC | 77 ms
76,308 KB |
testcase_18 | AC | 81 ms
77,848 KB |
testcase_19 | AC | 75 ms
77,984 KB |
testcase_20 | AC | 58 ms
66,416 KB |
testcase_21 | AC | 80 ms
76,360 KB |
testcase_22 | AC | 62 ms
66,436 KB |
testcase_23 | AC | 75 ms
75,492 KB |
testcase_24 | AC | 73 ms
77,492 KB |
testcase_25 | AC | 59 ms
70,408 KB |
testcase_26 | AC | 53 ms
70,408 KB |
testcase_27 | AC | 44 ms
62,184 KB |
testcase_28 | AC | 47 ms
70,408 KB |
testcase_29 | AC | 62 ms
68,564 KB |
testcase_30 | AC | 74 ms
76,972 KB |
testcase_31 | AC | 61 ms
70,620 KB |
testcase_32 | AC | 47 ms
70,380 KB |
testcase_33 | AC | 54 ms
62,212 KB |
ソースコード
import sys input = sys.stdin.readline MOD = 998244353 def nPk(n, k): ret = 1 for i in range(n, n - k, -1): ret *= i ret %= MOD return ret N, M, K = map(int, input().split()) edges = [[x - 1 for x in map(int, input().split())] for _ in [0] * K] toposo_st = set([]) for edge in edges: toposo_st |= set(edge) toposo_ids = { x : i for i, x in enumerate(toposo_st)} t = len(toposo_st) def can_set_left(s, i): for x, y in edges: if(toposo_ids[y] != i): continue if((s >> toposo_ids[x]) & 1): return False return True dp = [-1] * (1 << t) dp[0] = 1 def count_toposo(s): global dp if(dp[s] == -1): dp[s] = 0 for i in range(t): if not((s >> i) & 1): continue if(can_set_left(s, i)): dp[s] += count_toposo(s - (1 << i)) dp[s] %= MOD return dp[s] ans = 0 p1 = nPk(N - 1, N - t) p2 = nPk(N - 1, N - t - 1) for i in range(M, N): if(i in toposo_st): id = toposo_ids[i] if not(can_set_left((1 << t) - 1, id)): continue ans += p1 * count_toposo((1 << t) - 1 - (1 << id)) % MOD else: ans += p2 * count_toposo((1 << t) - 1) % MOD ans %= MOD print(ans)