結果

問題 No.3017 交互浴
ユーザー Cafe1942
提出日時 2025-01-25 13:52:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,384 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 94,612 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2025-01-25 23:01:22
合計ジャッジ時間 19,980 ms
ジャッジサーバーID
(参考情報)
judge3 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using ll = long long;
using namespace std;
#define modP 998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;cin >> N;
    stack<pair<ll,pair<int,ll>>>ST;
    ST.push({ (ll)1e10,{0,(ll)1e10} });
    ll ans = 0;
    for (int i = 0;i < N;i++) {
        ll H;cin >> H;
        while (ST.top().first <= H) {
            if (ST.top().second.first == 1) {
                ans -= ST.top().second.second;
            }
            ST.pop();
        }
        if (ST.top().second.first == i % 2) {
            if(ST.top().second.first==1)ans -= H - (ST.top().first - ST.top().second.second);
            ST.top().second.second = ST.top().first - H;
            ST.push({ H,{1 - i % 2, H} });
            if (i % 2 == 0)ans += H;
        }
        else {
            if (ST.top().second.first == 1)ans += ST.top().first - ST.top().second.second;
            ST.top().second.second = ST.top().first;
        }
        cout << ans << endl;
    }
    return 0;
}
0