結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー Ameesh SethiAmeesh Sethi
提出日時 2024-06-21 22:42:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,222 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 97,408 KB
最終ジャッジ日時 2024-06-24 18:46:01
合計ジャッジ時間 2,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
61,568 KB
testcase_01 AC 54 ms
61,952 KB
testcase_02 AC 54 ms
61,696 KB
testcase_03 AC 59 ms
63,872 KB
testcase_04 AC 59 ms
64,000 KB
testcase_05 AC 55 ms
62,848 KB
testcase_06 AC 58 ms
64,128 KB
testcase_07 AC 58 ms
64,128 KB
testcase_08 AC 58 ms
64,000 KB
testcase_09 AC 57 ms
62,720 KB
testcase_10 AC 58 ms
63,872 KB
testcase_11 AC 58 ms
63,744 KB
testcase_12 AC 108 ms
91,776 KB
testcase_13 AC 100 ms
90,496 KB
testcase_14 AC 103 ms
94,336 KB
testcase_15 AC 83 ms
81,408 KB
testcase_16 AC 105 ms
95,360 KB
testcase_17 AC 104 ms
95,232 KB
testcase_18 AC 78 ms
79,232 KB
testcase_19 AC 78 ms
78,848 KB
testcase_20 AC 86 ms
84,224 KB
testcase_21 AC 54 ms
61,696 KB
testcase_22 AC 53 ms
61,952 KB
testcase_23 AC 106 ms
97,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
def input(): return stdin.readline()[:-1]

MOD = 998244353

MAXN = (10 ** 5 * 2) + 23
fact = [1] * MAXN
for i in range(1, MAXN):
    fact[i] = fact[i - 1] * i % MOD
inverse = [1] * MAXN
inverse[MAXN - 1] = pow(fact[MAXN - 1], MOD - 2, MOD)
for i in range(MAXN - 2, 0, -1):
    inverse[i] = inverse[i + 1] * (i + 1) % MOD

def comb(n, k):
    ans = fact[n] * inverse[k] % MOD
    ans = ans * inverse[n - k] % MOD
    return ans

def func(x, y):
    r, l = x - 1, y - 1
    return comb(r + l, r)
    

def solve():
    n = int(input())
    arr = list(map(int, input().split()))
    arr.append(0)
    
    t = [(1, arr[0] + 1)]
    for i in range(1, n + 1 ):
        if arr[i] == arr[i - 1]:
            row = i + 1
            right = arr[i] + 1 - 1
            t.append((row, right))
        else:
            row = i + 1
            right = arr[i] + 1
            t.append((row, right))
            right += 1
            while right <= arr[i - 1]:
                nrow = row - 1
                t.append((nrow, right))
                right += 1
    
    
    ans = 0
    for x, y in t:
        # print(x, y , func(x, y))
        ans += func(x, y)
        ans %= MOD
    print(ans)
    
    
solve()
0