結果

問題 No.3017 交互浴
ユーザー YFYF
提出日時 2025-01-25 13:47:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 4,086 ms
コンパイル使用メモリ 253,620 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-25 22:59:48
合計ジャッジ時間 27,669 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N;
    cin >> N;

    stack<pair<int,int>> sta;
    sta.push({0,1000000001});

    long long res = 0;

    rep(i,N){
        int h;
        cin >> h;

        int index = 1;

        if(i % 2 == 0){
            int index = 0;
        }
        while(true){
            auto p = sta.top();

            if(p.second < h){
                if(index % 2){
                    if(i % 2 == 0){
                        res += p.second - p.first;
                    }else{
                        res -= p.second - p.first;
                    }
                }
                sta.pop();
                index++;
            }else{
                // cout << index <<" " <<i <<endl; 
                if(index % 2 ==0){
                    int temp = p.second;
                    sta.pop();
                    sta.push({0,p.second});
                }else{
                    int temp = p.second;
                    if(i % 2 == 0){
                        res += h - p.first;
                    }else{
                        res -= h - p.first; 
                    }
                    sta.pop();
                    sta.push({h,p.second});
                    sta.push({0,h});
                }

                break;
            }
            
        }

        // auto temp2 = sta;
        // while(!temp2.empty()){
        //     auto j = temp2.top();
        //     temp2.pop();
        //     cout << "{"<<j.first <<" " << j.second << "}";
        // }

        cout << res << endl;
    }
}
0