結果
問題 | No.2048 L(I+D)S |
ユーザー |
|
提出日時 | 2024-11-03 13:50:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 2,498 bytes |
コンパイル時間 | 523 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 97,568 KB |
最終ジャッジ日時 | 2024-11-03 13:50:06 |
合計ジャッジ時間 | 4,094 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
def II(): return int(input())def MI(): return map(int, input().split())def TI(): return tuple(MI())def LI(): return list(MI())#str-inputdef SI(): return input()def MSI(): return input().split()def SI_L(): return list(SI())def SI_LI(): return list(map(int, SI()))#multiple-inputdef LLI(n): return [LI() for _ in range(n)]def LSI(n): return [SI() for _ in range(n)]#1-indexを0-indexでinputdef MI_1(): return map(lambda x:int(x)-1, input().split())def TI_1(): return tuple(MI_1())def LI_1(): return list(MI_1())class fenwick_tree():n=1data=[0 for i in range(n)]def __init__(self,N):self.n=Nself.data=[0 for i in range(N)]def add(self,p,x):assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n)p+=1while(p<=self.n):self.data[p-1]+=xp+=p& -pdef sum(self,l,r):assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n)return self.sum0(r)-self.sum0(l)def sum0(self,r):s=0while(r>0):s+=self.data[r-1]r-=r&-rreturn smod = 998244353class Comb: #combination列挙def __init__(self,lim,mod = mod):"""mod : prime指定lim以下のmodでcomdination計算"""self.fac = [1,1]self.inv = [1,1]self.finv = [1,1]self.mod = modfor i in range(2,lim+1):self.fac.append(self.fac[i-1]*i%self.mod)self.inv.append(-self.inv[mod%i]*(mod//i)%self.mod)self.finv.append(self.finv[i-1]*self.inv[i]%self.mod)def F(self,a):return self.fac[a]def C(self,a,b):#自然な拡張assert b >= 0, "第2引数の値が負です"if a < b: return 0if a < 0: return 0# 0 <= a ∧ b <= a (b < 0でバグる)return self.fac[a]*self.finv[b]*self.finv[a-b]%self.moddef P(self,a,b):assert b >= 0, "第2引数の値が負です"if a < b: return 0if a < 0: return 0return self.fac[a]*self.finv[a-b]%self.moddef H(self,a,b):return self.C(a+b-1,b)def Fi(self,a):return self.finv[a]n = II()comb = Comb(n+1)#縦の長さans = 0for i in range(2,n-1):j = n-i #最長減少di = pow(i,-1,mod)dj = pow(j,-1,mod)dij = pow(i+j-1,-1,mod)ans += (comb.F(n)*comb.Fi(i-2)*comb.Fi(j-2)%mod*di*dj*dij%mod)**2print(ans%mod)