結果
問題 | No.2522 Fall in love, Girls! |
ユーザー | MasKoaTS |
提出日時 | 2023-08-28 15:22:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 243 ms / 2,000 ms |
コード長 | 1,382 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 81,736 KB |
実行使用メモリ | 84,244 KB |
最終ジャッジ日時 | 2023-10-27 20:50:28 |
合計ジャッジ時間 | 4,188 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,512 KB |
testcase_01 | AC | 37 ms
53,512 KB |
testcase_02 | AC | 37 ms
53,512 KB |
testcase_03 | AC | 223 ms
84,196 KB |
testcase_04 | AC | 37 ms
53,512 KB |
testcase_05 | AC | 36 ms
53,512 KB |
testcase_06 | AC | 66 ms
70,660 KB |
testcase_07 | AC | 53 ms
62,168 KB |
testcase_08 | AC | 77 ms
74,444 KB |
testcase_09 | AC | 52 ms
59,340 KB |
testcase_10 | AC | 57 ms
67,536 KB |
testcase_11 | AC | 57 ms
67,536 KB |
testcase_12 | AC | 57 ms
60,012 KB |
testcase_13 | AC | 76 ms
72,412 KB |
testcase_14 | AC | 243 ms
84,244 KB |
testcase_15 | AC | 228 ms
83,984 KB |
testcase_16 | AC | 237 ms
84,244 KB |
testcase_17 | AC | 98 ms
78,104 KB |
testcase_18 | AC | 95 ms
77,708 KB |
testcase_19 | AC | 88 ms
78,220 KB |
testcase_20 | AC | 70 ms
68,576 KB |
testcase_21 | AC | 96 ms
76,060 KB |
testcase_22 | AC | 72 ms
66,512 KB |
testcase_23 | AC | 96 ms
77,352 KB |
testcase_24 | AC | 94 ms
78,368 KB |
testcase_25 | AC | 68 ms
70,364 KB |
testcase_26 | AC | 63 ms
70,364 KB |
testcase_27 | AC | 53 ms
62,140 KB |
testcase_28 | AC | 54 ms
70,364 KB |
testcase_29 | AC | 75 ms
68,592 KB |
testcase_30 | AC | 90 ms
77,320 KB |
testcase_31 | AC | 80 ms
73,256 KB |
testcase_32 | AC | 55 ms
70,336 KB |
testcase_33 | AC | 64 ms
62,168 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) graph = [[0] * t for _ in [0] * t] for x, y in edges: graph[toposo_ids[x]][toposo_ids[y]] = 1 def can_set_left(s, i): for j in range(t): if(i == j or not((s >> j) & 1)): continue if(graph[j][i] == 0): continue 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)