結果

問題 No.1378 Flattening
ユーザー mkawa2mkawa2
提出日時 2022-06-28 02:16:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,470 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 80,728 KB
最終ジャッジ日時 2023-08-12 20:24:36
合計ジャッジ時間 12,963 ms
ジャッジサーバーID
(参考情報)
judge7 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,120 KB
testcase_01 AC 66 ms
71,188 KB
testcase_02 AC 69 ms
71,348 KB
testcase_03 AC 67 ms
71,404 KB
testcase_04 AC 73 ms
71,448 KB
testcase_05 AC 66 ms
71,124 KB
testcase_06 AC 71 ms
71,352 KB
testcase_07 AC 65 ms
70,972 KB
testcase_08 AC 67 ms
71,164 KB
testcase_09 AC 69 ms
71,176 KB
testcase_10 AC 67 ms
71,452 KB
testcase_11 AC 69 ms
71,232 KB
testcase_12 AC 66 ms
71,300 KB
testcase_13 AC 66 ms
71,440 KB
testcase_14 AC 67 ms
71,364 KB
testcase_15 AC 68 ms
70,968 KB
testcase_16 AC 65 ms
71,360 KB
testcase_17 AC 65 ms
71,264 KB
testcase_18 AC 65 ms
70,968 KB
testcase_19 AC 66 ms
71,464 KB
testcase_20 AC 67 ms
71,196 KB
testcase_21 AC 66 ms
71,468 KB
testcase_22 AC 67 ms
71,268 KB
testcase_23 AC 66 ms
71,224 KB
testcase_24 AC 68 ms
71,376 KB
testcase_25 AC 67 ms
71,196 KB
testcase_26 AC 68 ms
71,224 KB
testcase_27 AC 67 ms
71,456 KB
testcase_28 AC 68 ms
71,336 KB
testcase_29 AC 67 ms
71,444 KB
testcase_30 AC 66 ms
71,260 KB
testcase_31 WA -
testcase_32 AC 565 ms
80,544 KB
testcase_33 WA -
testcase_34 AC 474 ms
80,184 KB
testcase_35 AC 429 ms
80,156 KB
testcase_36 AC 410 ms
80,296 KB
testcase_37 WA -
testcase_38 AC 427 ms
80,256 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 423 ms
80,320 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 124 ms
77,752 KB
testcase_46 AC 149 ms
77,788 KB
testcase_47 AC 100 ms
77,112 KB
testcase_48 WA -
testcase_49 AC 381 ms
80,088 KB
testcase_50 WA -
testcase_51 AC 77 ms
76,016 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
cs = [0]+[1]*(n+1)

for i, a in enumerate(aa):
    ndp = [0]*(n+1)
    ncs = [0]*(n+2)
    l, r = ll[i], rr[i]
    for j in range(n+1):
        ndp[j]=dp[j]
        if l <= j <= r and (j > i or r < n):
            if l == 0 and j>i:
                ndp[j] += cs[i+1]-cs[l]
            else:
                ndp[j] += cs[j]-cs[l]
        ncs[j+1] = (ncs[j]+ndp[j])%md
    dp = ndp
    cs = ncs

print(dp[n])
0