結果

問題 No.1294 マウンテン数列
ユーザー vwxyzvwxyz
提出日時 2022-09-27 05:22:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 513 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 12,960 KB
最終ジャッジ日時 2023-08-24 03:35:00
合計ジャッジ時間 5,484 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
12,300 KB
testcase_01 AC 25 ms
7,868 KB
testcase_02 AC 25 ms
7,788 KB
testcase_03 AC 29 ms
7,736 KB
testcase_04 AC 30 ms
7,856 KB
testcase_05 AC 598 ms
8,344 KB
testcase_06 AC 776 ms
8,340 KB
testcase_07 AC 19 ms
7,976 KB
testcase_08 AC 20 ms
7,824 KB
testcase_09 AC 20 ms
7,948 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

N=int(readline())
A=list(map(int,readline().split()))
M=2500
cnt=[0]*M
mod=998244353
for d in range(M-1,-1,-1):
    if any(A[i+1]-A[i]>d for i in range(N-1)):
        break
    dp=[0]*(N+1)
    r=N
    dp[N-1]=1
    for l in range(N-3,-1,-1):
        while A[r-1]-A[l]>d:
            r-=1
        dp[l+1]=(dp[l+2]+dp[l+2]-dp[r])%mod
    cnt[d]=dp[1]*2%mod
for i in range(M-1,0,-1):
    cnt[i]-=cnt[i-1]
    cnt[i]%=mod
ans=sum(d*cnt[d]%mod for d in range(M))%mod
print(ans)
0