結果

問題 No.1294 マウンテン数列
ユーザー mkawa2mkawa2
提出日時 2024-01-05 00:35:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 806 ms / 2,000 ms
コード長 1,634 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 224,144 KB
最終ジャッジ日時 2024-01-05 00:35:40
合計ジャッジ時間 6,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
68,800 KB
testcase_01 AC 61 ms
68,804 KB
testcase_02 AC 55 ms
66,196 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 147 ms
93,224 KB
testcase_06 AC 165 ms
99,752 KB
testcase_07 AC 37 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 806 ms
224,144 KB
testcase_11 AC 752 ms
224,144 KB
testcase_12 AC 733 ms
224,016 KB
testcase_13 AC 730 ms
218,332 KB
testcase_14 AC 637 ms
194,912 KB
testcase_15 AC 676 ms
212,496 KB
testcase_16 AC 614 ms
194,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(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-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n=II()
aa=LI()

l=max(aa[i+1]-aa[i] for i in range(n-1))
h=aa[-1]-aa[0]
# pDB(l,h)

dp=[[0]*(h+1) for _ in range(n)]
cs0=[[0]*(h+2) for _ in range(n+1)]
cs1=[[0]*(h+2) for _ in range(n+1)]
for i,a in enumerate(aa[1:],1):
    j=i
    for d in range(l,h+1):
        while j and a-aa[j-1]<d:j-=1
        # dp[i][d]=sum(dp[k][d] for k in range(j+1,i))
        if j+1<i:dp[i][d]=cs0[i][d]-cs0[j+1][d]
        if j and a-aa[j-1]==d and l<d+1:
            # dp[i][d]+=sum(dp[j][e] for e in range(l,d+1))
            dp[i][d] += cs1[j][d+1]-cs1[j][l]
        if d==l:dp[i][d]+=1
        dp[i][d]%=md
        cs0[i+1][d]=(cs0[i][d]+dp[i][d])%md
        cs1[i][d+1]=(cs1[i][d]+dp[i][d])%md
# dp[-1][l]+=1
# p2D(dp)

ans=l
for i in range(1,n):
    for d in range(l,h+1):
        ans+=dp[i][d]*max(aa[-1]-aa[i-1],d)%md
        ans%=md
        # pDB(i,d,dp[i][d],ans)
print(ans)
0