結果

問題 No.2522 Fall in love, Girls!
ユーザー MasKoaTSMasKoaTS
提出日時 2023-10-27 13:30:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 97,364 KB
最終ジャッジ日時 2023-10-27 20:50:37
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
85,608 KB
testcase_01 AC 122 ms
85,608 KB
testcase_02 AC 116 ms
85,608 KB
testcase_03 AC 278 ms
97,268 KB
testcase_04 AC 118 ms
85,600 KB
testcase_05 AC 116 ms
85,608 KB
testcase_06 AC 146 ms
88,872 KB
testcase_07 AC 135 ms
88,544 KB
testcase_08 AC 157 ms
88,872 KB
testcase_09 AC 129 ms
85,924 KB
testcase_10 AC 140 ms
94,120 KB
testcase_11 AC 141 ms
94,116 KB
testcase_12 AC 140 ms
86,400 KB
testcase_13 AC 163 ms
96,796 KB
testcase_14 AC 320 ms
97,364 KB
testcase_15 AC 294 ms
97,088 KB
testcase_16 AC 311 ms
97,256 KB
testcase_17 AC 173 ms
91,988 KB
testcase_18 AC 170 ms
90,584 KB
testcase_19 AC 166 ms
91,996 KB
testcase_20 AC 155 ms
88,816 KB
testcase_21 AC 172 ms
88,956 KB
testcase_22 AC 154 ms
88,744 KB
testcase_23 AC 175 ms
90,584 KB
testcase_24 AC 169 ms
91,988 KB
testcase_25 AC 152 ms
96,744 KB
testcase_26 AC 148 ms
96,740 KB
testcase_27 AC 142 ms
88,516 KB
testcase_28 AC 136 ms
96,740 KB
testcase_29 AC 156 ms
88,848 KB
testcase_30 AC 169 ms
91,960 KB
testcase_31 AC 159 ms
88,844 KB
testcase_32 AC 141 ms
96,800 KB
testcase_33 AC 151 ms
88,560 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