結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:45:03 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,767 bytes |
| 記録 | |
| コンパイル時間 | 1,230 ms |
| コンパイル使用メモリ | 159,596 KB |
| 実行使用メモリ | 7,552 KB |
| 最終ジャッジ日時 | 2026-04-18 01:45:11 |
| 合計ジャッジ時間 | 6,292 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 WA * 20 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
const int MAXQ = 800005;
char st[MAXQ]; // 簡約化された状態を保持するスタック
int ptr_history[MAXQ]; // Sの長さ L に対するスタックの有効な長さを保存
int main() {
// 入出力の高速化
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
if (!(cin >> Q)) return 0;
int current_S_len = 0;
ptr_history[0] = 0;
for (int i = 0; i < Q; ++i) {
int type;
cin >> type;
if (type == 1) {
char c;
cin >> c;
// 現在のスタックの「有効な末尾」の次の位置を取得
int cur_ptr = ptr_history[current_S_len];
// 新しい文字をスタックに書き込む
st[cur_ptr] = c;
cur_ptr++;
// 末尾が (|) になったか判定
if (cur_ptr >= 3 &&
st[cur_ptr - 3] == '(' &&
st[cur_ptr - 2] == '|' &&
st[cur_ptr - 1] == ')') {
cur_ptr -= 3; // (|) を消去
}
current_S_len++;
ptr_history[current_S_len] = cur_ptr;
} else {
// クエリ2: Sの末尾を削除するだけ
// ptr_historyに以前の状態が保存されているので、長さを戻すだけでOK
if (current_S_len > 0) {
current_S_len--;
}
}
// ptr_history[current_S_len] が 0 なら全ての括弧が消えたことになる
if (ptr_history[current_S_len] == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}