結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 03:58:19 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 944 bytes |
| 記録 | |
| コンパイル時間 | 1,539 ms |
| コンパイル使用メモリ | 166,304 KB |
| 実行使用メモリ | 19,108 KB |
| 最終ジャッジ日時 | 2026-04-18 03:58:37 |
| 合計ジャッジ時間 | 9,826 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
struct Node {
char c;
int prev;
int size;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
vector<Node> nodes = {{'\0', -1, 0}};
vector<int> history = {0};
while (Q--) {
int type;
cin >> type;
if (type == 1) {
char c;
cin >> c;
int cur = history.back();
if (c == ')' && nodes[cur].size >= 2 &&
nodes[cur].c == '|' && nodes[nodes[cur].prev].c == '(') {
history.push_back(nodes[nodes[cur].prev].prev);
} else {
history.push_back(nodes.size());
nodes.push_back({c, cur, nodes[cur].size + 1});
}
} else {
history.pop_back();
}
cout << (nodes[history.back()].size == 0 ? "Yes" : "No") << "\n";
}
return 0;
}