結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 18:05:10 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,250 bytes |
| 記録 | |
| コンパイル時間 | 2,809 ms |
| コンパイル使用メモリ | 182,028 KB |
| 実行使用メモリ | 116,608 KB |
| 最終ジャッジ日時 | 2026-04-18 18:05:42 |
| 合計ジャッジ時間 | 20,043 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 RE * 28 |
コンパイルメッセージ
main.cpp: In member function 'Node* Node::get_child(char)':
main.cpp:36:5: warning: control reaches end of non-void function [-Wreturn-type]
36 | }
| ^
ソースコード
#include <string>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<n; ++i)
struct Node {
char c;
Node* p;
int status = -1;
array<Node*, 3> child = {nullptr, nullptr, nullptr};
Node(Node* p, char c): p(p), c(c) {}
Node* get_child(char c) {
if(c == '(') {
if(child[0] == nullptr) {
child[0] = new Node(this, '(');
}
return child[0];
}
if(c == '|') {
if(child[1] == nullptr) {
child[1] = new Node(this, '|');
}
return child[1];
}
if(c == ')') {
if(child[2] == nullptr) {
child[2] = new Node(this, ')');
}
return child[2];
}
}
};
int main() {
Node* root = new Node(nullptr, '$');
Node* current = root;
ll q;
cin >> q;
vector<char> query(q);
rep(i, q) {
ll type;
cin >> type;
if(type == 1) {
cin >> query[i];
current = current->get_child(query[i]);
}
else {
query[i] = ' ';
current = current->p;
}
}
stack<char> st;
st.push('(');
auto f = [&](auto&& f, Node* v) -> void {
char need = st.top();
if(need == v->c) {
if(need == '(') {
st.pop();
st.push('|');
}
if(need == '|') {
st.pop();
st.push(')');
}
if(need == ')') {
st.pop();
}
}
v->status = st.size();
if(st.empty()) st.push('(');
rep(i, 3) if(v->child[i] != nullptr) f(f, v->child[i]);
if(st.top() == '(' && st.size() == 1) st.pop();
if(need == v->c && (need == '(' || need == '|')) {
st.pop();
}
if(need == v->c) {
st.push(need);
}
};
f(f, root->get_child('('));
current = root;
rep(i, q) {
if(query[i] != ' ') current = current->get_child(query[i]);
else current = current->p;
cout << (current->status == 0 ? "Yes" : "No") << "\n";
}
}