結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-10-20 19:41:31 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 789 bytes |
| コンパイル時間 | 378 ms |
| コンパイル使用メモリ | 82,416 KB |
| 実行使用メモリ | 82,968 KB |
| 最終ジャッジ日時 | 2025-10-20 19:41:38 |
| 合計ジャッジ時間 | 7,052 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
from collections.abc import Iterable
def accum_dp1(xs: Iterable, f, op, e: int, size: int, init: Iterable, *, is_reset=True):
dp = [e] * size
for i, v in init:
dp[i] = v
for x in xs:
pp = [e] * size if is_reset else dp.copy()
dp, pp = pp, dp
for i in range(size):
for p, v in f(i, pp[i], x):
if 0 <= p < size:
dp[p] = op(dp[p], v)
return dp
MOD = 998244353
N = int(input())
A = list(map(int, input().split()))
def f(i, v, x):
return [(i-x, v), (i+x, v)]
def op(a, b):
return (a + b) % MOD
size = 20010
offset = size // 2
dp = accum_dp1(A, f, op, 0, size, [(offset, 1)])
ans = 0
for i in range(size):
x = i - offset
ans += abs(x) * dp[i]
ans %= MOD
print(ans)
norioc