結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
aorinngo0606
|
| 提出日時 | 2026-04-19 08:20:40 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,211 bytes |
| 記録 | |
| コンパイル時間 | 2,301 ms |
| コンパイル使用メモリ | 337,228 KB |
| 実行使用メモリ | 7,976 KB |
| 最終ジャッジ日時 | 2026-04-19 08:21:09 |
| 合計ジャッジ時間 | 21,553 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 RE * 10 |
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
typedef long double lb;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> bool chmin(T& a, const T& b){if(a > b){a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b){if(a < b){a = b; return 1;} return 0;}
const ll INF = 1000000000000000000; // 10^18
int main(){
/*
0 = (
1 = |
2 = )
*/
ll q;
cin >> q;
stack<ll> a;
ll cnt = 0; // 今の文字数
string s = "";
ll num = 0; // 有効な文字数
rep(i,q){
ll tmp;
cin >> tmp;
if(tmp == 1){
char c;
cin >> c;
if(num == cnt){
if(c == '('){
a.push(1);
cnt++;
num++;
s += "(";
}else if(c == '|' && a.top() == 1){
a.pop();
a.push(2);
cnt++;
num++;
s += "|";
}else if(c == ')' && a.top() == 2){
a.pop();
cnt++;
num++;
s += ")";
}
}else{
cnt++;
s += "#";
}
}
if(tmp == 2){
if(num == cnt){
cnt--;
num--;
if(s[s.size()-1] == '(') {
a.pop();
}
else if(s[s.size()-1] == '|'){
a.pop();
a.push(1);
}
else if(s[s.size()-1] == ')'){
a.push(2);
}
}else{
cnt--;
}
s.erase(s.size()-1);
}
if(a.empty() && num == cnt){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
return 0;
}
aorinngo0606