結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 22:43:53 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 51 ms / 2,000 ms |
| + 566µs | |
| コード長 | 1,673 bytes |
| 記録 | |
| コンパイル時間 | 2,122 ms |
| コンパイル使用メモリ | 334,888 KB |
| 実行使用メモリ | 12,456 KB |
| 最終ジャッジ日時 | 2026-09-08 00:37:29 |
| 合計ジャッジ時間 | 10,889 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}