結果

問題 No.1294 マウンテン数列
ユーザー vwxyzvwxyz
提出日時 2022-09-27 05:22:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 513 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-06-02 00:48:20
合計ジャッジ時間 5,520 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
16,128 KB
testcase_01 AC 39 ms
10,624 KB
testcase_02 AC 39 ms
10,880 KB
testcase_03 AC 43 ms
10,880 KB
testcase_04 AC 42 ms
10,752 KB
testcase_05 AC 606 ms
10,880 KB
testcase_06 AC 821 ms
10,880 KB
testcase_07 AC 35 ms
10,880 KB
testcase_08 AC 35 ms
10,752 KB
testcase_09 AC 34 ms
10,624 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