結果
問題 |
No.3017 交互浴
|
ユーザー |
![]() |
提出日時 | 2025-01-27 08:02:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 884 bytes |
コンパイル時間 | 3,838 ms |
コンパイル使用メモリ | 280,652 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2025-01-27 08:02:15 |
合計ジャッジ時間 | 12,404 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; template<class T>using V=vector<T>; template<class T>using VV=V<V<T>>; const ll INF=2e18; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V<ll> H(n); rep(i,n) cin>>H[i]; stack<pair<ll,ll>> st; V<ll> ANS(n); st.push({-INF,0}); for(int i=0;i<n;i++){ while(abs(st.top().first)<=H[i]){ auto a=st.top(); st.pop(); } ll tmp=st.top().second; if(i%2==0){ if(st.top().first<0){ ANS[i]=tmp+H[i]; st.push({H[i],ANS[i]}); } else ANS[i]=tmp; } else{ if(st.top().first>0){ ANS[i]=tmp-H[i]; st.push({-H[i],ANS[i]}); } else ANS[i]=tmp; } } rep(i,n) cout<<ANS[i]<<'\n'; return 0; }