結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-01-25 13:24:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 2,191 ms |
コンパイル使用メモリ | 198,744 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-25 22:45:44 |
合計ジャッジ時間 | 9,697 ms |
ジャッジサーバーID (参考情報) |
judge8 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; stack<pair<int,int>> st; st.emplace(1 << 30, 1); int ans = 0; for(int i = 0; i < n; i++){ int v; cin >> v; while(v >= st.top().first){ auto [v, t] = st.top(); st.pop(); ans -= (t == 0 ? v : -v); } int at = i & 1; if (at != st.top().second){ st.emplace(v, at); ans += (at == 0 ? v : -v); } cout << ans << '\n'; } }