結果

問題 No.1670 Many Gacha
ユーザー chineristACchineristAC
提出日時 2021-03-04 03:53:59
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,783 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 846,292 KB
最終ジャッジ日時 2023-08-21 18:48:12
合計ジャッジ時間 5,379 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
78,232 KB
testcase_01 AC 119 ms
78,068 KB
testcase_02 AC 482 ms
95,136 KB
testcase_03 AC 149 ms
81,612 KB
testcase_04 AC 120 ms
78,264 KB
testcase_05 AC 152 ms
81,724 KB
testcase_06 AC 123 ms
78,220 KB
testcase_07 AC 132 ms
79,116 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, mod):#コンビネーションの高速計算 
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

mod = 998244353#出力の制限
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def solve(N,M,A):
    A = [0] + A
    dp = [[[0 for j in range(A[m-1]*(m>0)+1)] for i in range(A[m]-A[m-1]*(m>0)+1)] for m in range(M+1)]

    for m in range(1,M+1):
        if m!=1:
            for j in range(A[m-1]+1):
                inv = g2[A[m-1]] * g1[A[m-1]-j] * g1[j] % mod
                for k in range(A[m-1]-A[m-2]+1):
                    tmp = cmb(A[m-1]-A[m-2],k,mod) * cmb(A[m-2],j-k,mod)
                    if not tmp:
                        continue
                    tmp *= inv * dp[m-1][k][j-k]
                    tmp %= mod
                    dp[m][0][j] += tmp
                    dp[m][0][j] %= mod

        for i in range(1,A[m]-A[m-1]+1):
            for j in range(A[m-1]+1):
                dp[m][i][j] = A[m] + i * dp[m][i-1][j] + j * dp[m][i][j-1]
                dp[m][i][j] %= mod
                dp[m][i][j] *= inverse[i+j]
                dp[m][i][j] %= mod

    return dp[M][A[M]-A[M-1]][A[M-1]]

N,M = mi()
A = li()
print(solve(N,M,A))
0