結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-02-11 19:22:17 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 853 bytes |
コンパイル時間 | 1,059 ms |
コンパイル使用メモリ | 90,784 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-02-11 19:22:31 |
合計ジャッジ時間 | 12,297 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 WA * 40 |
ソースコード
#include <iostream>#include <cstdint>#include <vector>#include <stack>using namespace std;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int32_t N, i;cin >> N;vector<int32_t> H(N);for (i = 0; i != N; ++i) cin >> H[i];stack<int32_t> s;int32_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(), 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(), s.pop();if (H[i] <= s.top()) break;else lower = s.top(), s.pop();}cout << ans << '\n';}return 0;}