結果

問題 No.3117 Reversible Tile
ユーザー titia
提出日時 2025-04-23 02:39:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 573 ms / 3,000 ms
コード長 655 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 77,332 KB
最終ジャッジ日時 2025-04-23 02:39:57
合計ジャッジ時間 10,024 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

N,M=map(int,input().split())
A=list(map(int,input().split()))

A=[0]+A+[0]

now=0
for i in range(len(A)-1):
    if A[i]!=A[i+1]:
        now+=1

DP=[0]*(N+2)
DP[now]=1

#print(DP)

for i in range(M):
    NDP=[0]*(N+2)

    # same
    for j in range(N+2):
        NDP[j]+=DP[j]*j*(N+1-j)%mod
        
    # 二個減らす
    for j in range(N+2):
        if j-2>=0:
            NDP[j-2]+=DP[j]*(j*(j-1)//2)%mod
            
    # 二個増やす
    for j in range(N+2):
        if j+2<N+2:
            x=N+1-j
            NDP[j+2]+=DP[j]*(x*(x-1)//2)%mod

    DP=NDP
    #print(DP)

print(DP[0]%mod)
0