結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:42:33 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,853 bytes |
| 記録 | |
| コンパイル時間 | 1,742 ms |
| コンパイル使用メモリ | 158,492 KB |
| 実行使用メモリ | 8,320 KB |
| 最終ジャッジ日時 | 2026-04-18 01:42:44 |
| 合計ジャッジ時間 | 9,929 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 WA * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 最大クエリ数に応じた配列サイズ
const int MAXQ = 800005;
char st[MAXQ]; // 簡約化されたスタック
int pos[MAXQ]; // 文字列Sの各文字がスタックのどこに対応するかを記録
char raw_s[MAXQ]; // 文字列Sそのものを記録
int main() {
// 高速入出力
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
int current_s_len = 0; // 現在の文字列Sの長さ
int st_ptr = 0; // 簡約スタックの現在のポインタ
for (int i = 0; i < Q; ++i) {
int type;
cin >> type;
if (type == 1) {
char c;
cin >> c;
current_s_len++;
raw_s[current_s_len] = c;
// 簡約スタックに文字を追加
st[st_ptr] = c;
st_ptr++;
// 末尾が (|) になったらスタックポインタを3つ戻す
if (st_ptr >= 3 &&
st[st_ptr - 3] == '(' &&
st[st_ptr - 2] == '|' &&
st[st_ptr - 1] == ')') {
st_ptr -= 3;
}
// 現在のSの長さにおける「スタックの深さ」を保存
pos[current_s_len] = st_ptr;
} else {
// クエリ2: Sの末尾を削除
current_s_len--;
// 文字列Sが短くなったので、スタックのポインタを
// 「短くなった後のSの末尾」が指していた位置に戻す
st_ptr = pos[current_s_len];
}
// 簡約スタックが空なら Yes
if (st_ptr == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}