結果
問題 | No.2792 Security Cameras on Young Diagram |
ユーザー |
![]() |
提出日時 | 2024-06-22 00:12:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 2,627 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 92,928 KB |
最終ジャッジ日時 | 2024-06-24 18:48:20 |
合計ジャッジ時間 | 3,453 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import sysfrom collections import defaultdict, deque, Counterfrom heapq import heapify, heappush, heappop, mergefrom bisect import bisect_right, bisect_leftleft_binser = lower_bound = bisect_left ; right_binser = upper_bound = bisect_rightfrom itertools import permutations, combinations, accumulatedef 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 % modinv_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) % modreturn fact, inv_factdef comb(n, k, fact, inv_fact, mod):if k < 0 or k > n:return 0return 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 GeneratorTypeMOD = 10**9 + 7_MOD = 998244353YES = "YES"NO = "NO"ALICE = "Alice"BOB = "Bob"def FLOOR_DIV(a, b) :return a // bdef 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(2 * 10**5, _MOD)n = getone()arr = getarr()arr = [arr[0]] + arrans = 0for i in range(1, n + 1) :ver,hor = i - 1, arr[i] - 1ans = (ans + comb(ver + hor, ver, f, inv_f, _MOD)) % _MODif 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)) % _MODfor hor in range(0, arr[-1]) :ans = (ans + comb(n - 1 + hor, hor, f, inv_f, _MOD)) % _MODans %= _MODreturn ans""""""testcase = ""# testcase = "multiple" # Multiple tcif testcase == "multiple" :for i in range(int(input())) :print(solve())# solve()...else :print(solve())# solve()...