結果

問題 No.2511 Mountain Sequence
ユーザー titiatitia
提出日時 2023-11-19 03:20:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 722 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 165,560 KB
最終ジャッジ日時 2023-11-19 03:21:04
合計ジャッジ時間 17,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
146,608 KB
testcase_01 AC 111 ms
146,608 KB
testcase_02 AC 486 ms
159,016 KB
testcase_03 AC 164 ms
150,692 KB
testcase_04 AC 300 ms
161,356 KB
testcase_05 AC 283 ms
164,512 KB
testcase_06 AC 477 ms
159,016 KB
testcase_07 AC 432 ms
161,696 KB
testcase_08 AC 201 ms
162,188 KB
testcase_09 AC 152 ms
151,452 KB
testcase_10 AC 522 ms
161,712 KB
testcase_11 AC 614 ms
162,732 KB
testcase_12 AC 108 ms
146,608 KB
testcase_13 AC 601 ms
161,624 KB
testcase_14 AC 628 ms
163,724 KB
testcase_15 AC 642 ms
162,636 KB
testcase_16 AC 698 ms
160,028 KB
testcase_17 AC 600 ms
165,560 KB
testcase_18 AC 531 ms
161,720 KB
testcase_19 AC 525 ms
161,928 KB
testcase_20 AC 524 ms
162,224 KB
testcase_21 AC 579 ms
165,304 KB
testcase_22 AC 544 ms
161,680 KB
testcase_23 AC 314 ms
158,348 KB
testcase_24 AC 345 ms
158,352 KB
testcase_25 AC 722 ms
158,348 KB
testcase_26 AC 263 ms
158,352 KB
testcase_27 AC 478 ms
158,352 KB
testcase_28 AC 77 ms
102,144 KB
testcase_29 AC 527 ms
162,248 KB
testcase_30 AC 543 ms
162,184 KB
testcase_31 AC 531 ms
162,208 KB
testcase_32 AC 572 ms
161,624 KB
testcase_33 AC 645 ms
164,296 KB
testcase_34 AC 538 ms
161,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

FACT=[1]
for i in range(1,3*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(3*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod
    else:
        return 0

N,M=map(int,input().split())
ANS=0

if N==M==1:
    print(1)
    exit()

"""
for x in range(1,M):
    for j in range(N+1):
        ANS+=Combi(x,j)*Combi(x,N-1-j)

    #print(ANS)

print(ANS%mod)
"""

F2=[1,1]

for i in range(2,6*10**5+1):
    F2.append(F2[-2]*i%mod)

def calc(x,y):
    if y==x*2+1:
        return 1
    if x-y//2>=0:
        A1=FACT[x]*pow(FACT[x-y//2],mod-2,mod)
    else:
        A1=0

    if 2*x-1-(y-1)//2*2>=0:
        A2=F2[2*x-1]*pow(F2[2*x-1-(y-1)//2*2],mod-2,mod)
    else:
        A2=0

    C1=FACT[(y-1)//2]
    C2=F2[y//2*2-1]

    #print(A1,A2,C1,C2)

    if y%2==0:
        A1*=2

    return A1*A2*pow(C1*C2,mod-2,mod)%mod

for x in range(1,M):
    ANS+=calc(x,N)

    #if calc(x,N)>0:
    #    print(x,calc(x,N))

    #X=0

    #for j in range(N+1):
    #    X+=Combi(x,j)*Combi(x,N-1-j)

    #print((x,N),calc(x,N),X)


print(ANS%mod)
    
0