結果

問題 No.3017 交互浴
コンテスト
ユーザー ooaiu
提出日時 2025-02-01 20:18:26
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 4,507 ms
コンパイル使用メモリ 277,436 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-01 20:18:37
合計ジャッジ時間 11,323 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    cin >> N;
    vector<pair<int, int>> st;
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
        int H;
        cin >> H;
        while(!st.empty() && st.back().first <= H) {
            auto[h, p] = st.back();
            st.pop_back();
            if(p & 1) ans += h;
            else ans -= h;
        }
        if(!st.empty() && st.back().second == i % 2);
        else {
            if(i % 2 == 0) {
                ans += H;
                st.push_back({H, i % 2});
            }else {
                ans -= H;
                if(!st.empty()) st.push_back({H, i % 2});
            }
        }
        cout << ans << '\n';
    }
}
0