結果

問題 No.2135 C5
ユーザー tassei903tassei903
提出日時 2022-11-26 08:56:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 535 ms / 2,000 ms
コード長 1,869 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 77,116 KB
最終ジャッジ日時 2024-04-10 11:23:13
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,044 KB
testcase_01 AC 43 ms
53,532 KB
testcase_02 AC 45 ms
52,996 KB
testcase_03 AC 251 ms
76,808 KB
testcase_04 AC 40 ms
54,280 KB
testcase_05 AC 42 ms
53,020 KB
testcase_06 AC 40 ms
54,084 KB
testcase_07 AC 43 ms
53,808 KB
testcase_08 AC 41 ms
54,200 KB
testcase_09 AC 40 ms
53,928 KB
testcase_10 AC 38 ms
53,352 KB
testcase_11 AC 38 ms
53,092 KB
testcase_12 AC 40 ms
52,768 KB
testcase_13 AC 38 ms
52,744 KB
testcase_14 AC 39 ms
53,916 KB
testcase_15 AC 130 ms
76,660 KB
testcase_16 AC 126 ms
76,936 KB
testcase_17 AC 264 ms
76,832 KB
testcase_18 AC 111 ms
76,748 KB
testcase_19 AC 62 ms
67,316 KB
testcase_20 AC 79 ms
74,000 KB
testcase_21 AC 75 ms
72,316 KB
testcase_22 AC 97 ms
76,564 KB
testcase_23 AC 386 ms
77,116 KB
testcase_24 AC 149 ms
76,752 KB
testcase_25 AC 40 ms
52,736 KB
testcase_26 AC 38 ms
53,440 KB
testcase_27 AC 38 ms
53,504 KB
testcase_28 AC 38 ms
53,212 KB
testcase_29 AC 426 ms
77,100 KB
testcase_30 AC 139 ms
76,604 KB
testcase_31 AC 251 ms
76,812 KB
testcase_32 AC 141 ms
76,584 KB
testcase_33 AC 41 ms
53,872 KB
testcase_34 AC 42 ms
52,332 KB
testcase_35 AC 41 ms
54,292 KB
testcase_36 AC 42 ms
52,948 KB
testcase_37 AC 40 ms
53,220 KB
testcase_38 AC 39 ms
53,212 KB
testcase_39 AC 40 ms
53,760 KB
testcase_40 AC 40 ms
53,440 KB
testcase_41 AC 43 ms
55,048 KB
testcase_42 AC 38 ms
53,812 KB
testcase_43 AC 38 ms
52,896 KB
testcase_44 AC 40 ms
53,540 KB
testcase_45 AC 300 ms
77,032 KB
testcase_46 AC 65 ms
69,392 KB
testcase_47 AC 164 ms
76,692 KB
testcase_48 AC 41 ms
52,904 KB
testcase_49 AC 535 ms
77,060 KB
testcase_50 AC 39 ms
53,616 KB
testcase_51 AC 41 ms
53,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
mod = 998244353
nn = 400
fact = [1] * nn
for i in range(nn - 1):
    fact[i + 1] = fact[i] * (i + 1) % mod
invfact = [1] * nn
invfact[nn - 1] = pow(fact[nn - 1], mod - 2, mod)
for i in range(nn - 1)[::-1]:
    invfact[i] = invfact[i + 1] * (i + 1) % mod
 
def binom(x, y):
    if x < 0 or y < 0 or x - y < 0:
        return 0
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod

n,m = na()
m = n*(n-1)//2 - m
if m > n:
    print(0)
    exit()
mod = 998244353

cycle = [0]*nn
for i in range(3,nn):
    cycle[i] = fact[i-1]*pow(2,mod-2,mod)%mod
cycle[2] = 1
path = [0]*nn
for i in range(2,nn):
    path[i] = fact[i]*pow(2,mod-2,mod)%mod
path[1] = 1
dp = [[0 for j in range(m+1)]for i in range(n+1)]

dp[0][0] = 1
for j in range(m+1):
    for i in range(n+1):
        for k in range(5,n+1):
            ni = i + k
            nj = j + k
            if ni > n or nj > m:
                break
            #print(binom(n-i-1, k-1),cycle[k])
            """if ni == 5 and nj == 4:
                print(i, j, k, dp[i][j] * binom(n-i-1, k-1) % mod * cycle[k] % mod)"""
            dp[ni][nj] += dp[i][j] * binom(n-i-1, k-1) % mod * cycle[k] % mod
            dp[ni][nj] %= mod
        for k in range(1,n+1):
            ni = i + k
            nj = j + k - 1
            if ni > n or nj > m:
                break
            #print(binom(n-i-1, k-1),path[k])
            dp[ni][nj] += dp[i][j] * binom(n-i-1, k-1) % mod * path[k] % mod
            dp[ni][nj] %= mod
        #print(dp)
ans = dp[-1][-1]

print(ans)
0