結果

問題 No.2522 Fall in love, Girls!
ユーザー MasKoaTSMasKoaTS
提出日時 2023-10-27 13:30:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 98,176 KB
最終ジャッジ日時 2024-09-25 13:16:52
合計ジャッジ時間 7,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
86,464 KB
testcase_01 AC 134 ms
86,272 KB
testcase_02 AC 128 ms
86,272 KB
testcase_03 AC 300 ms
98,176 KB
testcase_04 AC 131 ms
86,224 KB
testcase_05 AC 130 ms
86,456 KB
testcase_06 AC 160 ms
89,728 KB
testcase_07 AC 149 ms
89,292 KB
testcase_08 AC 168 ms
89,600 KB
testcase_09 AC 143 ms
86,656 KB
testcase_10 AC 148 ms
94,592 KB
testcase_11 AC 147 ms
94,684 KB
testcase_12 AC 146 ms
86,784 KB
testcase_13 AC 175 ms
97,524 KB
testcase_14 AC 350 ms
98,048 KB
testcase_15 AC 327 ms
98,084 KB
testcase_16 AC 332 ms
98,048 KB
testcase_17 AC 193 ms
92,672 KB
testcase_18 AC 190 ms
91,136 KB
testcase_19 AC 181 ms
93,028 KB
testcase_20 AC 166 ms
89,472 KB
testcase_21 AC 183 ms
89,856 KB
testcase_22 AC 166 ms
89,856 KB
testcase_23 AC 188 ms
91,008 KB
testcase_24 AC 183 ms
92,672 KB
testcase_25 AC 165 ms
97,792 KB
testcase_26 AC 160 ms
97,792 KB
testcase_27 AC 148 ms
88,960 KB
testcase_28 AC 152 ms
97,152 KB
testcase_29 AC 171 ms
89,548 KB
testcase_30 AC 185 ms
92,928 KB
testcase_31 AC 171 ms
89,476 KB
testcase_32 AC 152 ms
97,408 KB
testcase_33 AC 167 ms
89,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools as iter
import collections as coll
import heapq as hq
import bisect as bis
from decimal import Decimal as dec
from functools import cmp_to_key
import math
import sys
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10 ** 6)
inp = sys.stdin.readline
input = lambda : inp()[:-1]
getN = lambda : int(inp())
getNs = lambda : map(int, inp().split())
getList = lambda :list(map(int, inp().split()))
getStrs = lambda n : [input() for _ in [0] * n]
getEdges = lambda n : [[x - 1 for x in getNs()] for _ in [0] * n]
def yexit(): print("Yes"); exit(0)
def nexit(): print("No"); exit(0)
pi = 3.141592653589793
mod = 1000000007
MOD = 998244353
INF = 4611686018427387903
dx = [1, 0, -1, 0];  dy = [0, 1, 0, -1]
#di = coll.defaultdict(int)

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

N, M, K = getNs()
edges = getEdges(K)

A = set([])
for x, y in edges:
    A |= set([x, y])
t = len(A)
id_A = { x : i for i, x in enumerate(sorted(A)) }
graph = [[0] * t for _ in [0] * t]
for x, y in edges:
    graph[id_A[x]][id_A[y]] = 1

def can_set_left(s, i):
    for j in range(t):
        if not((s >> j) & 1 and graph[j][i]):
            continue
        return False
    return True

dp = [-1] * (1 << t)
dp[0] = 1
def count_toposo(s):
    if(dp[s] == -1):
        dp[s] = 0
        for i in range(t):
            if not((s >> i) & 1 and can_set_left(s, i)):
                continue
            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 A):
        id = id_A[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)
0