結果
問題 | No.3017 交互浴 |
ユーザー |
![]() |
提出日時 | 2025-01-25 14:16:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 3,120 ms |
コンパイル使用メモリ | 144,600 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-25 23:13:48 |
合計ジャッジ時間 | 22,031 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge7 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <set> #include <deque> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; #define rep(i, n) for (int i = 0; i< (int)(n); i++) int op(int a, int b){ return a+b; } int e(){return 0;} int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; deque<pair<ll, int>> dq; vector<ll> sum(2, 0); rep(i, n){ ll h; cin >> h; int c = (i%2 == 0 ? 1 : 0); if(dq.size() == 0 && c == 1){ dq.push_back({h, c}); sum[c] += h; }else{ while(!dq.empty() && dq.back().first <= h){ sum[dq.back().second] -= dq.back().first; dq.pop_back(); }if(dq.size() == 0){ if(c == 1){ dq.push_back({h, c}); sum[c] += h; } }else if(dq.back().second != c){ dq.push_back({h, c}); sum[c] += h; } } cout << sum[1] - sum[0] << endl; } return 0; }