結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー aldyasaldyas
提出日時 2024-06-22 00:11:54
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,623 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 84,912 KB
最終ジャッジ日時 2024-06-22 00:11:58
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
62,908 KB
testcase_01 AC 52 ms
63,360 KB
testcase_02 AC 52 ms
62,416 KB
testcase_03 AC 56 ms
63,232 KB
testcase_04 AC 56 ms
65,344 KB
testcase_05 AC 55 ms
63,116 KB
testcase_06 AC 56 ms
65,268 KB
testcase_07 AC 56 ms
63,304 KB
testcase_08 AC 57 ms
63,852 KB
testcase_09 AC 56 ms
63,516 KB
testcase_10 AC 55 ms
64,332 KB
testcase_11 AC 57 ms
64,596 KB
testcase_12 AC 94 ms
83,732 KB
testcase_13 AC 84 ms
80,704 KB
testcase_14 RE -
testcase_15 AC 74 ms
74,852 KB
testcase_16 AC 88 ms
84,316 KB
testcase_17 RE -
testcase_18 AC 68 ms
72,472 KB
testcase_19 AC 77 ms
75,004 KB
testcase_20 AC 82 ms
79,828 KB
testcase_21 AC 63 ms
62,232 KB
testcase_22 AC 55 ms
63,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

from collections import defaultdict, deque, Counter
from heapq import heapify, heappush, heappop, merge
from bisect import bisect_right, bisect_left 
left_binser = lower_bound = bisect_left ; right_binser = upper_bound = bisect_right
from itertools import permutations, combinations, accumulate


def precompute_factorials_and_inverses(max_n, mod):
        fact = [1] * (max_n + 1)
        inv_fact = [1] * (max_n + 1)
        for i in range(2, max_n + 1):
            fact[i] = fact[i-1] * i % mod
        inv_fact[max_n] = pow(fact[max_n], mod-2, mod)
        for i in range(max_n - 1, 0, -1):
            inv_fact[i] = inv_fact[i+1] * (i+1) % mod
        return fact, inv_fact

def comb(n, k, fact, inv_fact, mod):
    if k < 0 or k > n:
        return 0
    return fact[n] * inv_fact[k] % mod * inv_fact[n-k] % mod


# from math import lcm,gcd
# from math import comb, perm
# from functools import lru_cache
# from types import GeneratorType

MOD = 10**9 + 7
_MOD = 998244353

YES = "YES"
NO = "NO"
ALICE = "Alice"
BOB = "Bob"

def FLOOR_DIV(a, b) :
    return a // b
def CEIL_DIV(a, b) :
    return (a // b) + (not(not(a % b)))

def get() :
    return map(int, sys.stdin.readline().split())
def getone() :
    return int(sys.stdin.readline().strip())
def getstr() :
    return sys.stdin.readline().split()
def getonestr() :
    return sys.stdin.readline().strip()
def getarr() :
    return list(map(int, sys.stdin.readline().split()))

def _3d_ARRAY_SPAWN(i, j, k) :
    return [[[0 for _k in range(k)] for _j in range(j)] for _i in range(i)]
def _2d_ARRAY_SPAWN(i, j) :
    return [[0 for _j in range(j)] for _i in range(i)]
   
"""
"never doubt that u can't do this, cause it's an insult to ur determination"
by @deepakgoswami0552 10/03/2024
""" 

def solve() :
    ...
    # Solution here!
    f,inv_f = precompute_factorials_and_inverses(10**5, _MOD)

    n = getone()
    arr = getarr()
    arr = [arr[0]] + arr


    ans = 0
    for i in range(1, n + 1) :

        ver,hor = i - 1, arr[i] - 1
        ans = (ans + comb(ver + hor, ver, f, inv_f, _MOD)) % _MOD

        if arr[i] < arr[i - 1]:
            for hor_ in range(hor + 1, arr[i - 1]) :
                ans = (ans + comb(ver - 1 + hor_, ver - 1, f, inv_f, _MOD)) % _MOD
        

    for hor in range(0, arr[-1]) :
        ans = (ans + comb(n - 1 + hor, hor, f, inv_f, _MOD)) % _MOD

    ans %= _MOD
    return ans

""""""
testcase = ""
# testcase = "multiple" # Multiple tc


if testcase == "multiple" :

    for i in range(int(input())) : 
        print(solve())
        # solve()
        ...
else :
    print(solve())
    # solve()
    ...
0