結果
問題 |
No.3058 Deque and Brackets
|
ユーザー |
|
提出日時 | 2025-03-15 00:12:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 2,148 ms |
コンパイル使用メモリ | 201,004 KB |
実行使用メモリ | 7,328 KB |
最終ジャッジ日時 | 2025-03-15 00:12:15 |
合計ジャッジ時間 | 5,006 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<tuple<char,int,int>> LR(2*N); for(auto &[c,l,r] : LR) cin >> c >> l >> r; long long answer = 0; priority_queue<int> Q; int okl = 0,okr = 0; for(int i=2*N; i--;){ auto [c,l,r] = LR.at(i); if(c == ')'){ if(l <= r) okr++,answer += r; else okl--,answer += l,Q.push(r-l); } else{ if(l >= r) okl++,answer += l; else okr--,answer += r,Q.push(l-r); } if(okl < 0 || okr < 0){ answer += Q.top(); Q.pop(); okl++; okr++; } } cout << answer << endl; }