結果

問題 No.3017 交互浴
ユーザー ponjuice
提出日時 2025-02-22 02:33:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 3,348 ms
コンパイル使用メモリ 278,960 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-22 02:33:30
合計ジャッジ時間 28,321 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(){
    ll n;
    cin >> n;
    stack<pair<ll,ll>> 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;
    }
}
0