結果
| 問題 |
No.1645 AB's abs
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-10-20 19:39:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 789 bytes |
| コンパイル時間 | 438 ms |
| コンパイル使用メモリ | 82,284 KB |
| 実行使用メモリ | 78,332 KB |
| 最終ジャッジ日時 | 2025-10-20 19:39:26 |
| 合計ジャッジ時間 | 5,868 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 17 |
ソースコード
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 = 10010
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