結果
| 問題 |
No.3058 Deque and Brackets
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-03-14 22:04:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 2,000 ms |
| コード長 | 1,055 bytes |
| コンパイル時間 | 4,480 ms |
| コンパイル使用メモリ | 255,724 KB |
| 実行使用メモリ | 7,760 KB |
| 最終ジャッジ日時 | 2025-03-14 22:04:48 |
| 合計ジャッジ時間 | 9,194 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000000
#define Inf64 1000000000000000001LL
int main(){
int n;
cin>>n;
vector<char> c(n*2);
vector<long long> l(n*2),r(n*2);
rep(i,n*2){
cin>>c[i]>>l[i]>>r[i];
}
long long ans = 0;
reverse(c.begin(),c.end());
reverse(l.begin(),l.end());
reverse(r.begin(),r.end());
priority_queue<long long,vector<long long>,greater<long long>> q,q2;
int x = 0, y=0;
rep(i,n*2){
if(c[i]=='('){
if(l[i]>=r[i]){
ans += l[i];
x++;
}
else{
y--;
ans += r[i];
q.push(r[i]-l[i]);
if(y<0){
y++;
x++;
ans -= q.top();
q.pop();
}
}
}
else{
if(l[i]<=r[i]){
ans += r[i];
y++;
}
else{
x--;
ans += l[i];
q.push(l[i]-r[i]);
if(x<0){
x++;
y++;
ans -= q.top();
q.pop();
}
}
}
//cout<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}
沙耶花