結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー miya145592miya145592
提出日時 2024-06-21 23:28:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 140,724 KB
最終ジャッジ日時 2024-06-21 23:28:28
合計ジャッジ時間 4,779 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
119,276 KB
testcase_01 AC 125 ms
120,108 KB
testcase_02 AC 122 ms
119,488 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 105 ms
120,072 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def nPr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

def nCr(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

import sys
input = sys.stdin.readline
MOD = 998244353
N = int(input())
A = list(map(int, input().split()))

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
fact = [1, 1]

for i in range( 2, 2*10**5 + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )
    fact.append( (fact[-1] * i) % MOD )

A.append(0)
ans = dict()
for i in range(N):
    a = A[i]
    if i not in ans:
        ans[i] = nCr(i+a, a, MOD)
    a2 = A[i+1]
    aa = max(a2, a-1)
    ans[i+1] = nCr(i+1+aa, aa, MOD)
#print(ans)
ans2 = 0       
bk = -1
for i in range(N, -1, -1):
    if bk==A[i]:
        continue
    ans2 += ans[i]
    ans2 %= MOD
    bk = A[i]
print(ans2)
0