結果
| 問題 | No.3017 交互浴 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-22 02:33:00 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 198 ms / 2,000 ms |
| コード長 | 1,049 bytes |
| 記録 | |
| コンパイル時間 | 1,893 ms |
| コンパイル使用メモリ | 340,396 KB |
| 実行使用メモリ | 9,264 KB |
| 最終ジャッジ日時 | 2026-07-05 02:59:41 |
| 合計ジャッジ時間 | 15,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 55 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) begin(a), end(a)
#define rep(i,a,b) for(ll i = a; i < (b); i++)
int main(){
ll n;
cin >> n;
stack<pair<ll,ll>> st;
ll res = 0;
rep(i,0,n){
ll h;
cin >> h;
if(i % 2 == 0){
while(st.size() && st.top().second <= h){
res -= st.top().second - st.top().first;
st.pop();
}
if(st.size() && st.top().first < h){
res -= h - st.top().first;
st.top().first = 0;
res += h;
}else{
st.push({0,h});
res += h;
}
}else{
while(st.size() && st.top().second <= h){
res -= st.top().second - st.top().first;
st.pop();
}
if(st.size() && st.top().first < h){
res -= h - st.top().first;
st.top().first = h;
}
}
cout << res << endl;
}
}