結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-01-25 14:22:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 3,264 ms |
コンパイル使用メモリ | 278,400 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-25 23:18:21 |
合計ジャッジ時間 | 25,409 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#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){ st.push({h.h,false}); ans -= h.h; } } cout << ans << endl; } return 0; }