結果
問題 |
No.3017 交互浴
|
ユーザー |
![]() |
提出日時 | 2025-01-31 22:49:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 336 ms / 2,000 ms |
コード長 | 574 bytes |
コンパイル時間 | 2,420 ms |
コンパイル使用メモリ | 196,388 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-31 22:49:31 |
合計ジャッジ時間 | 25,782 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; const int INF = 2e9; vector<int> st{INF}; int cur = 0; for (int i = 0; i < n; i++) { int h; cin >> h; while (!st.empty() && st.back() <= h) { if (st.size() % 2) { cur += st.back(); } else { cur -= st.back(); } st.pop_back(); } if (st.size() % 2 != i % 2) { st.push_back(h); if (i % 2 == 0) { cur += h; } else { cur -= h; } } cout << cur << endl; } }