結果
| 問題 |
No.2528 pop_(backfront or not)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-12 02:53:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,327 bytes |
| コンパイル時間 | 288 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 206,080 KB |
| 最終ジャッジ日時 | 2024-09-26 02:59:30 |
| 合計ジャッジ時間 | 6,720 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 4 |
ソースコード
from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
N = int(input())
mod = 998244353
class combination():
def __init__(self,N,p):
self.fact = [1, 1] # fact[n] = (n! mod p)
self.factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
self.inv = [0, 1] # factinv 計算用
self.p = p
for i in range(2, N + 1):
self.fact.append((self.fact[-1] * i) % p)
self.inv.append((-self.inv[p % i] * (p // i)) % p)
self.factinv.append((self.factinv[-1] * self.inv[-1]) % p)
def cmb(self,n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.p
M = 2*N+1
C = combination(M,mod)
mem = [[-1]*(M+1) for _ in range(M+1)]
mem[0][0] = 1
# mem[2][0] = 1
def f(x,y):
x,y = max(x,y),min(x,y)
if mem[x][y]!=-1:
return mem[x][y]
if y<0:
return 0
if y==0:
mem[x][y] = C.cmb(x-1,2)*f(x-2,y)%mod
return mem[x][y]
mem[x][y] = (C.cmb(x-1,2)*f(x-2,y) + f(x-1,y-1)*((x-1)*(y-1)+1) + C.cmb(y-1,2)*f(x,y-2))%mod
return mem[x][y]
for i in range(1,M+1):
print(f(i-1,M-i))