結果

問題 No.1378 Flattening
ユーザー titiatitia
提出日時 2022-08-15 01:20:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,762 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 409,268 KB
最終ジャッジ日時 2024-04-09 03:53:54
合計ジャッジ時間 19,656 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,724 KB
testcase_01 AC 36 ms
53,956 KB
testcase_02 AC 37 ms
52,928 KB
testcase_03 AC 36 ms
53,352 KB
testcase_04 AC 36 ms
53,068 KB
testcase_05 AC 35 ms
53,036 KB
testcase_06 AC 36 ms
54,176 KB
testcase_07 AC 35 ms
52,812 KB
testcase_08 AC 36 ms
53,204 KB
testcase_09 AC 35 ms
52,752 KB
testcase_10 AC 38 ms
53,548 KB
testcase_11 AC 36 ms
53,556 KB
testcase_12 AC 36 ms
53,692 KB
testcase_13 AC 36 ms
53,616 KB
testcase_14 AC 37 ms
53,092 KB
testcase_15 AC 35 ms
52,896 KB
testcase_16 AC 36 ms
52,404 KB
testcase_17 AC 35 ms
53,184 KB
testcase_18 AC 35 ms
52,344 KB
testcase_19 AC 35 ms
53,256 KB
testcase_20 AC 35 ms
52,960 KB
testcase_21 AC 35 ms
53,076 KB
testcase_22 AC 35 ms
53,508 KB
testcase_23 AC 35 ms
52,816 KB
testcase_24 AC 36 ms
52,580 KB
testcase_25 AC 34 ms
52,612 KB
testcase_26 AC 36 ms
52,440 KB
testcase_27 AC 35 ms
52,548 KB
testcase_28 AC 36 ms
52,268 KB
testcase_29 AC 35 ms
53,412 KB
testcase_30 AC 35 ms
52,936 KB
testcase_31 AC 1,695 ms
409,268 KB
testcase_32 AC 1,762 ms
393,360 KB
testcase_33 AC 1,266 ms
338,368 KB
testcase_34 AC 1,181 ms
338,244 KB
testcase_35 AC 1,726 ms
408,716 KB
testcase_36 AC 1,246 ms
348,680 KB
testcase_37 AC 768 ms
277,012 KB
testcase_38 AC 764 ms
276,632 KB
testcase_39 AC 772 ms
276,564 KB
testcase_40 AC 756 ms
277,196 KB
testcase_41 AC 768 ms
276,768 KB
testcase_42 AC 773 ms
277,628 KB
testcase_43 AC 758 ms
277,220 KB
testcase_44 AC 773 ms
276,644 KB
testcase_45 AC 139 ms
91,932 KB
testcase_46 AC 176 ms
102,156 KB
testcase_47 AC 78 ms
79,172 KB
testcase_48 AC 602 ms
230,076 KB
testcase_49 AC 665 ms
250,648 KB
testcase_50 AC 125 ms
89,244 KB
testcase_51 AC 43 ms
60,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://atcoder.jp/contests/agc058/tasks/agc058_b
# で出題されたのでこちらでも通しておきます。

import sys
input = sys.stdin.readline

n=int(input())
A=list(map(int,input().split()))

A=[n+1-a for a in A]

mod=998244353

IND=[-1]*(n+1)

for i in range(n):
    IND[A[i]]=i

LEFT=[[] for i in range(n)]
RIGHT=[[] for i in range(n)]

for i in range(1,n+1):
    x=IND[i]

    RIGHT[x].append(i)

    for j in range(x-1,-1,-1):
        if A[j]<i:
            RIGHT[j].append(i)
        else:
            break

    for j in range(x+1,n):
        if A[j]<i:
            LEFT[j].append(i)
        else:
            break
        
DP=[[0]*(n+1) for i in range(n)]

for x in RIGHT[0]:
    DP[0][x]=1


for i in range(1,n):
    DPR=[0]*(n+1)
    DPL=[0]*(n+1)
    
    for j in range(1,n+1):
        if DP[i-1][j]==0:
            continue
        plus=DP[i-1][j]

        # left
        if IND[j]<i:
            DPL[j]+=plus
            DPR[0]+=plus
        else:
            DPR[j]+=plus

    #print(DPL,DPR)

    for j in range(n-1,-1,-1):
        DPL[j]=(DPL[j]+DPL[j+1])%mod

    for j in range(1,n+1):
        DPR[j]=(DPR[j]+DPR[j-1])%mod

    #print(DPL,DPR)

    for right in RIGHT[i]:
        DP[i][right]=DPR[right]

    for left in LEFT[i]:
        DP[i][left]=DPL[left]

print(sum(DP[-1])%mod)          
        
0