結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-02-22 02:32:46 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 1,052 bytes |
コンパイル時間 | 2,935 ms |
コンパイル使用メモリ | 279,960 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-02-22 02:33:17 |
合計ジャッジ時間 | 28,800 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(a) begin(a), end(a) #define rep(i,a,b) for(ll i = a; i < (b); i++) int main(){ int n; cin >> n; stack<pair<int,int>> st; ll res = 0; rep(i,0,n){ ll h; cin >> h; if(i % 2 == 0){ while(st.size() && st.top().second <= h){ res -= st.top().second - st.top().first; st.pop(); } if(st.size() && st.top().first < h){ res -= h - st.top().first; st.top().first = 0; res += h; }else{ st.push({0,h}); res += h; } }else{ while(st.size() && st.top().second <= h){ res -= st.top().second - st.top().first; st.pop(); } if(st.size() && st.top().first < h){ res -= h - st.top().first; st.top().first = h; } } cout << res << endl; } }