結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-02-11 19:25:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 1,111 ms |
コンパイル使用メモリ | 91,260 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-02-11 19:25:20 |
合計ジャッジ時間 | 8,035 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <iostream>#include <cstdint>#include <vector>#include <stack>using namespace std;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);uint32_t N, i;cin >> N;vector<uint32_t> H(N);for (i = 0; i != N; ++i) cin >> H[i];stack<uint32_t> s;uint32_t ans = 0, lower;for (i = 0; i != N; ++i){lower = 0;if (i & 1)while (true){if (H[i] < s.top()){ans -= H[i] - lower, s.push(H[i]);break;}ans -= s.top() - lower, s.pop();if (s.empty() || H[i] <= s.top())break;elselower = s.top(), s.pop();}elsewhile (true){if (s.empty() || H[i] < s.top()){ans += H[i] - lower, s.push(H[i]);break;}ans += s.top() - lower, s.pop();if (H[i] <= s.top()) break;else lower = s.top(), s.pop();}cout << ans << '\n';}return 0;}