結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 15:13:14 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,445 bytes |
| 記録 | |
| コンパイル時間 | 2,973 ms |
| コンパイル使用メモリ | 339,836 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2026-04-18 15:13:25 |
| 合計ジャッジ時間 | 9,007 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct Node {
char c;
int prev;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
vector<Node> nodes;
nodes.reserve(3 * Q);
vector<int> history;
history.reserve(Q + 1);
int top = -1; // empty
history.push_back(top);
for (int i = 0; i < Q; i++) {
int t;
cin >> t;
if (t == 1) {
char c;
cin >> c;
// push new node
nodes.push_back({c, top});
top = (int)nodes.size() - 1;
// try reduce "(|)"
if (top != -1) {
int a = top;
int b = nodes[a].prev;
if (b != -1) {
int c2 = nodes[b].prev;
if (c2 != -1) {
if (nodes[c2].c == '(' &&
nodes[b].c == '|' &&
nodes[a].c == ')') {
// remove 3 nodes
top = nodes[c2].prev;
}
}
}
}
} else {
// undo
history.pop_back();
top = history.back();
cout << (top == -1 ? "Yes\n" : "No\n");
continue;
}
history.push_back(top);
cout << (top == -1 ? "Yes\n" : "No\n");
}
return 0;
}