結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 21:44:02 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,840 bytes |
| 記録 | |
| コンパイル時間 | 1,514 ms |
| コンパイル使用メモリ | 179,932 KB |
| 実行使用メモリ | 26,880 KB |
| 最終ジャッジ日時 | 2026-04-18 21:44:30 |
| 合計ジャッジ時間 | 22,835 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 RE * 10 |
ソースコード
#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 {
Node *left, *parent;
Node(Node* left, Node* parent): left(left), parent(parent) {}
};
int main() {
stack<Node*> loc;
Node* root = new Node(nullptr, nullptr);
loc.emplace(root);
ll q;
cin >> q;
ll len = 0;
ll error = -1;
rep(i, q) {
ll type;
cin >> type;
if(type == 1) {
len++;
char c;
cin >> c;
if(error > len) {
cout << "No" << endl;
continue;
}
else if(c == '(') {
auto c2 = new Node(nullptr, loc.top());
auto c1 = new Node(c2, nullptr);
loc.emplace(c1);
} else if(c == '|') {
if(loc.top()->left == nullptr) {
error = len;
cout << "No" << endl;
continue;
} else {
loc.emplace(loc.top()->left);
}
} else {
if(loc.top()->parent == nullptr) {
error = len;
cout << "No" << endl;
continue;
} else {
loc.emplace(loc.top()->parent);
}
}
}
else {
len--;
if(len == error-1) {
error = -1;
} else if(len <= error) {
cout << "No" << endl;
continue;
}
else {
loc.pop();
}
}
if(loc.top() == root) {
cout << "Yes" << endl;
}else {
cout << "No" << endl;
}
}
}