結果

問題 No.1378 Flattening
ユーザー mkawa2mkawa2
提出日時 2022-06-28 09:00:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 525 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 83,048 KB
最終ジャッジ日時 2023-08-13 06:15:45
合計ジャッジ時間 12,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,080 KB
testcase_01 AC 73 ms
71,412 KB
testcase_02 AC 72 ms
71,220 KB
testcase_03 AC 72 ms
71,248 KB
testcase_04 AC 71 ms
71,248 KB
testcase_05 AC 72 ms
71,268 KB
testcase_06 AC 73 ms
71,480 KB
testcase_07 AC 73 ms
71,564 KB
testcase_08 AC 72 ms
71,252 KB
testcase_09 AC 73 ms
71,236 KB
testcase_10 AC 72 ms
71,352 KB
testcase_11 AC 72 ms
71,364 KB
testcase_12 AC 73 ms
71,460 KB
testcase_13 AC 71 ms
71,244 KB
testcase_14 AC 71 ms
71,408 KB
testcase_15 AC 72 ms
71,232 KB
testcase_16 AC 73 ms
71,240 KB
testcase_17 AC 73 ms
71,408 KB
testcase_18 AC 71 ms
71,512 KB
testcase_19 AC 70 ms
71,500 KB
testcase_20 AC 72 ms
71,252 KB
testcase_21 AC 70 ms
71,076 KB
testcase_22 AC 70 ms
71,500 KB
testcase_23 AC 70 ms
71,560 KB
testcase_24 AC 71 ms
71,244 KB
testcase_25 AC 71 ms
71,448 KB
testcase_26 AC 71 ms
71,080 KB
testcase_27 AC 72 ms
71,232 KB
testcase_28 AC 71 ms
71,116 KB
testcase_29 AC 70 ms
71,076 KB
testcase_30 AC 72 ms
71,360 KB
testcase_31 AC 525 ms
82,740 KB
testcase_32 AC 513 ms
82,736 KB
testcase_33 AC 484 ms
82,968 KB
testcase_34 AC 486 ms
82,936 KB
testcase_35 AC 513 ms
82,496 KB
testcase_36 AC 493 ms
82,968 KB
testcase_37 AC 442 ms
82,688 KB
testcase_38 AC 444 ms
83,048 KB
testcase_39 AC 444 ms
82,756 KB
testcase_40 AC 447 ms
82,864 KB
testcase_41 AC 454 ms
82,816 KB
testcase_42 AC 441 ms
82,464 KB
testcase_43 AC 434 ms
82,564 KB
testcase_44 AC 469 ms
82,864 KB
testcase_45 AC 124 ms
77,700 KB
testcase_46 AC 140 ms
77,728 KB
testcase_47 AC 90 ms
77,096 KB
testcase_48 AC 375 ms
81,000 KB
testcase_49 AC 417 ms
81,716 KB
testcase_50 AC 118 ms
77,676 KB
testcase_51 AC 76 ms
76,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

n = II()
aa = LI()

ll = [0]*n
rr = [0]*n

st = [(-1, -1)]
for i, a in enumerate(aa):
    while st[-1][-1] > a: st.pop()
    ll[i] = st[-1][0]+1
    st.append((i, a))
# pDB(ll)

st = [(n, -1)]
for i in range(n)[::-1]:
    a = aa[i]
    while st[-1][-1] > a: st.pop()
    rr[i] = st[-1][0]
    st.append((i, a))
# pDB(rr)

dp = [1]+[0]*n

for i, a in enumerate(aa):
    cs = [0]
    for v in dp: cs.append((cs[-1]+v)%md)
    l, r = ll[i], rr[i]
    sj = r
    if r == n: sj = i+1
    for j in range(r, l, -1):
        dp[j] += cs[j]-cs[l]
        dp[j] %= md

print(dp[n])
0