結果
問題 | No.3017 交互浴 |
ユーザー |
|
提出日時 | 2025-01-25 14:22:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 1,399 bytes |
コンパイル時間 | 4,243 ms |
コンパイル使用メモリ | 284,800 KB |
実行使用メモリ | 6,756 KB |
最終ジャッジ日時 | 2025-01-25 23:17:26 |
合計ジャッジ時間 | 27,089 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; cin >> n; vector<int> h(n,0); for (int i = 0;i < n;i++) { cin >> h[i]; } auto cmp = [](vector<int> a,vector<int> b) -> bool { return a[1] > b[1]; }; priority_queue<vector<int>,vector<vector<int>>,decltype(cmp)> p(cmp); int ans = 0; for (int i = 0;i < n;i++) { if (i % 2 == 0) { while (p.size() != 0 && (p.top())[1] <= h[i]) { ans -= (p.top())[1] - (p.top())[0]; p.pop(); } if (p.size() == 0 || h[i] <= (p.top())[0]) { ans += h[i]; p.push({0,h[i]}); } else { vector<int> temp = p.top(); ans -= temp[1] - temp[0]; p.pop(); ans += temp[1]; p.push({0,temp[1]}); } } else { while (p.size() != 0 && (p.top())[1] <= h[i]) { ans -= (p.top())[1] - (p.top())[0]; p.pop(); } if (p.size() != 0 && (p.top())[0] <= h[i]) { vector<int> temp = p.top(); p.pop(); ans -= temp[1] - temp[0]; temp[0] = h[i]; ans += temp[1] - temp[0]; p.push(temp); } } cout << ans << endl; } }