結果

問題 No.3017 交互浴
ユーザー shingo0909
提出日時 2025-01-25 14:19:53
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 3,461 ms
コンパイル使用メモリ 278,184 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-25 23:16:32
合計ジャッジ時間 25,219 ms
ジャッジサーバーID
(参考情報)
judge9 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdlib>
#include <math.h>
using namespace std;

using ll = long long;

struct x{
    int h;
    bool c;
};

int main(){
    int n;
    cin >> n;
    stack<x> st;
    int ans=0;
    for(int i=0;i<n;i++){
        x h;
        cin >> h.h;
        while(!st.empty() && st.top().h <=h.h){
            x x =st.top();
            st.pop();
            if(x.c){
                ans-=(x.h);
            }
            else{
                ans+=(x.h);
            }
        }
        if(i%2==0){
            if(st.empty() || !st.top().c){
                st.push({h.h,true});
                ans += h.h;

            }
        }else{
            if(st.empty() || st.top().c){
                if(!st.empty())ans -= h.h;
                st.push({h.h,false});
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}
0