結果
問題 | No.1294 マウンテン数列 |
ユーザー |
![]() |
提出日時 | 2020-11-21 11:39:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 217 ms / 2,000 ms |
コード長 | 555 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,140 KB |
実行使用メモリ | 76,804 KB |
最終ジャッジ日時 | 2024-07-23 15:29:34 |
合計ジャッジ時間 | 2,759 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
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)