結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 22:43:53 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 1,673 bytes |
| 記録 | |
| コンパイル時間 | 2,357 ms |
| コンパイル使用メモリ | 334,376 KB |
| 実行使用メモリ | 12,452 KB |
| 最終ジャッジ日時 | 2026-04-17 22:44:14 |
| 合計ジャッジ時間 | 11,079 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
struct Action {
int type;
bool bad_prev;
};
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int q;
cin >> q;
vector<int> st;
vector<Action> hist;
bool bad = false;
rep(qi, q) {
int t;
cin >> t;
if (t == 1) {
char c;
cin >> c;
Action act;
act.bad_prev = bad;
act.type = 3;
if (c == '(') {
st.push_back(0);
act.type = 0;
}
else if (c == '|') {
if (st.size() and st.back() == 0) {
st.back() = 1;
act.type = 1;
}
else {
bad = true;
}
}
else {
if (st.size() and st.back() == 1) {
st.pop_back();
act.type = 2;
}
else {
bad = true;
}
}
hist.push_back(act);
}
else {
Action act = hist.back();
hist.pop_back();
bad = act.bad_prev;
if (act.type == 0) {
st.pop_back();
}
else if (act.type == 1) {
st.back() = 0;
}
else if (act.type == 2) {
st.push_back(1);
}
}
if (!bad and !st.size()) puts("Yes"); else puts("No");
}
return 0;
}