結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-02-01 20:21:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 826 bytes |
コンパイル時間 | 5,489 ms |
コンパイル使用メモリ | 277,232 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-02-01 20:22:11 |
合計ジャッジ時間 | 13,396 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int N;cin >> N;vector<pair<int, int>> st;int64_t ans = 0;for(int i = 0; i < N; i++) {int H;cin >> H;while(!st.empty() && st.back().first <= H) {auto[h, p] = st.back();st.pop_back();if(p & 1) ans += h;else ans -= h;}if(!st.empty() && st.back().second == i % 2);else {if(i % 2 == 0) {ans += H;st.push_back({H, i % 2});}else {if(!st.empty()) {st.push_back({H, i % 2});ans -= H;}}}cout << ans << '\n';}}