結果
問題 | No.3017 交互浴 |
ユーザー |
![]() |
提出日時 | 2024-12-30 23:17:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 426 ms / 2,000 ms |
コード長 | 456 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 107,524 KB |
最終ジャッジ日時 | 2025-01-25 21:55:48 |
合計ジャッジ時間 | 17,118 ms |
ジャッジサーバーID (参考情報) |
judge8 / judge10 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
N = int(input()) H = list(map(int, input().split())) stk = [(10 ** 18, 1)] ans = 0 def query(h, cl): global ans while stk: pre_h, pre_cl = stk[-1] if h < pre_h: if pre_cl != cl: stk.append((h, cl)) ans -= h * cl break else: stk.pop() ans += pre_h * pre_cl print(ans) for i, h in enumerate(H): cl = 1 if i % 2 else -1 query(h, cl)