結果
問題 | No.3017 交互浴 |
ユーザー |
![]() |
提出日時 | 2025-01-25 13:25:53 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 327 ms / 2,000 ms |
コード長 | 781 bytes |
コンパイル時間 | 8,079 ms |
コンパイル使用メモリ | 260,844 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-25 22:47:04 |
合計ジャッジ時間 | 28,164 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge7 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> H(N + 1); for (int i = 1; i <= N; ++i) cin >> H[i]; stack<pair<int, int>> st; int ans = 0; int prev = 0; st.push(make_pair(1000000010, 0)); for (int i = 1; i <= N; ++i) { while (st.top().first <= H[i]) { if (st.top().second % 2 == 0) ans += st.top().first; else ans -= st.top().first; st.pop(); } if (st.top().second % 2 != i % 2) { if (i % 2 == 1) ans += H[i]; else ans -= H[i]; st.push(make_pair(H[i], i)); } cout << ans << endl; } return 0; }