結果
| 問題 | No.1505 Zero-Product Ranges |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-18 15:43:20 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 370 ms / 2,000 ms |
| コード長 | 1,121 bytes |
| 記録 | |
| コンパイル時間 | 276 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 104,720 KB |
| 最終ジャッジ日時 | 2026-01-18 15:43:36 |
| 合計ジャッジ時間 | 12,656 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
from collections.abc import Iterable
def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True):
dp = init.copy()
for x in xs:
pp = {} if is_reset else dp.copy()
dp, pp = pp, dp
for fm_key, fm_val in pp.items():
for to_key, to_val in f(fm_key, fm_val, x):
dp[to_key] = op(dp.get(to_key, e), to_val)
return dp
def op(a, b):
return a + b
def f(k, v, x):
t, b = k # (状態, 0を含むか)
match t:
case 0: # まだ取ってない
yield k, v
# 取る
nb = b | (x == 0)
yield (1, nb), v
case 1: # 取った
nb = b | (x == 0)
yield (1, nb), v # とり続ける
# ここで終了
if b:
yield (2, b), v
case 2: # 終了状態
yield k, v
case _:
assert False
N = int(input())
A = list(map(int, input().split()))
init = {(0, False): 1}
dp = accum_dp(A, f, op, 0, init)
ans = 0
for (t, b), v in dp.items():
if t in (1, 2) and b:
ans += v
print(ans)
norioc