結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-01-25 14:13:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 2,074 bytes |
コンパイル時間 | 4,493 ms |
コンパイル使用メモリ | 277,620 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-25 23:12:04 |
合計ジャッジ時間 | 25,273 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge10 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef local #include <debug.hpp> #else #define debug(...) #endif #define rep(i, n) for (int i = 0; i < n; i++) template <class T> istream& operator>>(istream& I, vector<T>& V) {for (T& X : V) I >> X; return I;} template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} vector<int> di = {-1, 1, 0, 0}, dj = {0, 0, -1, 1}; int inf = 2e9; long INF = 1e18; int main() { int n; cin >> n; vector<int> h(n); cin >> h; long ans = 0; vector<int> x; rep(i, n) { if (i % 2 == 0) { while (!x.empty() and x.back() < h[i]) { int s = x.size(); if (s & 1) { if (x.size() == 1) { ans -= x.back(); } else { // ans -= x.end()[-2] - x.back(); ans -= x.back(); } } else { // ans += x.end()[-2] - x.back(); ans += x.back(); } x.pop_back(); } if ((int)x.size() % 2 == 0) { ans += h[i]; x.push_back(h[i]); } } else { while (!x.empty() and x.back() < h[i]) { int s = x.size(); if (s & 1) { if (x.size() == 1) { ans -= x.back(); } else { // ans -= x.end()[-2] - x.back(); ans -= x.back(); } } else { // ans += x.end()[-2] - x.back(); ans += x.back(); } x.pop_back(); } if ((int)x.size() & 1) { ans -= h[i]; x.push_back(h[i]); } } debug(x); cout << ans << endl; } return 0; }