結果

問題 No.1294 マウンテン数列
ユーザー KudeKude
提出日時 2020-11-21 11:39:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 78,004 KB
最終ジャッジ日時 2023-09-30 21:42:34
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,696 KB
testcase_01 AC 95 ms
76,872 KB
testcase_02 AC 94 ms
76,504 KB
testcase_03 AC 74 ms
71,060 KB
testcase_04 AC 75 ms
71,352 KB
testcase_05 AC 105 ms
76,828 KB
testcase_06 AC 116 ms
77,028 KB
testcase_07 AC 83 ms
76,000 KB
testcase_08 AC 73 ms
71,292 KB
testcase_09 AC 79 ms
75,756 KB
testcase_10 AC 203 ms
77,628 KB
testcase_11 AC 207 ms
77,652 KB
testcase_12 AC 208 ms
77,692 KB
testcase_13 AC 204 ms
77,788 KB
testcase_14 AC 249 ms
77,644 KB
testcase_15 AC 197 ms
77,732 KB
testcase_16 AC 205 ms
78,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
n = int(input())
a = list(map(int, input().split()))[::-1]
difmax = max(ai - aj for ai, aj in zip(a, a[1:]))
amax = a[0]
sa = [0] * (amax + 1)
for d in range(difmax, amax + 1):
    dp = [0] * n
    s = dp[0] = 1
    l = 0
    for i in range(1, n):
        while a[l] - a[i] > d:
            s -= dp[l]
            s %= mod
            l += 1
        dp[i-1] += s
        dp[i-1] %= mod
        s += s
        s %= mod
    sa[d] = sum(dp) % mod
ans = sa[0]
ans += sum(i * (sa[i] - sa[i-1]) for i in range(1, amax + 1))
ans %= mod
print(ans)
0