結果
問題 | No.1378 Flattening |
ユーザー | mkawa2 |
提出日時 | 2022-06-28 02:17:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 578 ms / 2,000 ms |
コード長 | 1,477 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 81,976 KB |
実行使用メモリ | 79,400 KB |
最終ジャッジ日時 | 2024-11-20 11:32:55 |
合計ジャッジ時間 | 10,836 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,240 KB |
testcase_01 | AC | 42 ms
52,396 KB |
testcase_02 | AC | 41 ms
52,196 KB |
testcase_03 | AC | 41 ms
52,732 KB |
testcase_04 | AC | 41 ms
53,160 KB |
testcase_05 | AC | 41 ms
52,884 KB |
testcase_06 | AC | 41 ms
53,160 KB |
testcase_07 | AC | 42 ms
53,020 KB |
testcase_08 | AC | 41 ms
53,272 KB |
testcase_09 | AC | 41 ms
53,100 KB |
testcase_10 | AC | 41 ms
53,216 KB |
testcase_11 | AC | 42 ms
53,720 KB |
testcase_12 | AC | 42 ms
53,996 KB |
testcase_13 | AC | 42 ms
52,508 KB |
testcase_14 | AC | 40 ms
53,300 KB |
testcase_15 | AC | 42 ms
52,396 KB |
testcase_16 | AC | 42 ms
52,416 KB |
testcase_17 | AC | 41 ms
53,976 KB |
testcase_18 | AC | 42 ms
52,756 KB |
testcase_19 | AC | 41 ms
52,640 KB |
testcase_20 | AC | 41 ms
53,444 KB |
testcase_21 | AC | 41 ms
52,352 KB |
testcase_22 | AC | 40 ms
52,624 KB |
testcase_23 | AC | 40 ms
53,756 KB |
testcase_24 | AC | 41 ms
53,172 KB |
testcase_25 | AC | 40 ms
52,964 KB |
testcase_26 | AC | 40 ms
53,152 KB |
testcase_27 | AC | 40 ms
53,032 KB |
testcase_28 | AC | 41 ms
53,920 KB |
testcase_29 | AC | 40 ms
52,192 KB |
testcase_30 | AC | 40 ms
53,308 KB |
testcase_31 | AC | 478 ms
78,640 KB |
testcase_32 | AC | 578 ms
78,972 KB |
testcase_33 | AC | 395 ms
78,988 KB |
testcase_34 | AC | 485 ms
78,736 KB |
testcase_35 | AC | 442 ms
78,640 KB |
testcase_36 | AC | 426 ms
79,240 KB |
testcase_37 | AC | 419 ms
78,792 KB |
testcase_38 | AC | 435 ms
79,400 KB |
testcase_39 | AC | 420 ms
79,236 KB |
testcase_40 | AC | 420 ms
79,248 KB |
testcase_41 | AC | 434 ms
79,168 KB |
testcase_42 | AC | 408 ms
78,688 KB |
testcase_43 | AC | 417 ms
78,960 KB |
testcase_44 | AC | 430 ms
78,728 KB |
testcase_45 | AC | 108 ms
76,544 KB |
testcase_46 | AC | 132 ms
76,404 KB |
testcase_47 | AC | 74 ms
73,924 KB |
testcase_48 | AC | 353 ms
78,468 KB |
testcase_49 | AC | 386 ms
78,744 KB |
testcase_50 | AC | 105 ms
76,976 KB |
testcase_51 | AC | 49 ms
60,048 KB |
ソースコード
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]%md)