結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
KowerKoint2010
|
| 提出日時 | 2026-04-17 21:00:02 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 2,000 ms |
| コード長 | 1,385 bytes |
| 記録 | |
| コンパイル時間 | 3,467 ms |
| コンパイル使用メモリ | 335,936 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-17 21:00:37 |
| 合計ジャッジ時間 | 14,326 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i, n) for(ll i =0; i < ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B>
bool chmax(A& a, B b) { return a<b && (a=b, true); }
template <class A, class B>
bool chmin(A& a, B b) { return b<a && (a=b, true); }
void testcase() {
stack<char> stk;
stack<char> real;
int invalid = 0;
int q; cin >> q;
REP(t, q) {
int op; cin >> op;
if(op == 1) {
char c; cin >> c;
real.push(c);
if(invalid > 0) {
invalid++;
} else if(c == '(') {
stk.push('(');
} else if(c == '|') {
if(!stk.empty() && stk.top() == '(') stk.top() = '|';
else invalid++;
} else if(c == ')') {
if(!stk.empty() && stk.top() == '|') stk.pop();
else invalid++;
}
} else {
char c = real.top(); real.pop();
if(invalid > 0) invalid--;
else {
if(c == '(') {
assert(stk.top() == '(');
stk.pop();
} else if(c == '|') {
assert(stk.top() == '|');
stk.top() = '(';
} else if(c == ')') {
stk.push('|');
}
}
}
if(invalid == 0 && stk.empty()) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
testcase();
}
KowerKoint2010