This documentation is automatically generated by online-judge-tools/verification-helper
ヒストグラム中の最大長方形の面積を求めるアルゴリズム。スタックを用いた方法により、ビンの数の線形時間で計算できる。
largest_rectangle_in_histogram(heights: Sequence[int]) -> int
$N$ 個のビン heights
を持つヒストグラム中の最大長方形の面積を返す。計算量 $O(N)$
def largest_rectangle_in_histogram(heights):
heights = heights + [-1] # sentinel
ans = 0
stack = []
for i, height in enumerate(heights):
idx = i
while True:
if not stack or stack[-1][0] <= height:
stack.append((height, idx))
break
else:
h, l = stack.pop()
ans = max(h * (i - l), ans)
idx = l
return ans
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
raise NotImplementedError
NotImplementedError