結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー Qiu Tian
提出日時 2026-04-18 15:09:47
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,087 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,625 ms
コンパイル使用メモリ 343,348 KB
実行使用メモリ 57,968 KB
最終ジャッジ日時 2026-04-18 15:09:58
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

struct Frame {
    bool left_ok;
    bool has_pipe;
    bool right_ok;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q;
    cin >> Q;

    vector<vector<Frame>> hist_stk;
    vector<bool> hist_bad;

    vector<Frame> stk;
    bool bad = false;

    hist_stk.push_back(stk);
    hist_bad.push_back(bad);

    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            char c;
            cin >> c;

            if (!bad) {
                if (c == '(') {
                    stk.push_back({true, false, true});
                }
                else if (c == '|') {
                    if (stk.empty() || stk.back().has_pipe) {
                        bad = true;
                    } else {
                        stk.back().has_pipe = true;
                    }
                }
                else { // ')'
                    if (stk.empty()) {
                        bad = true;
                    } else {
                        Frame f = stk.back();
                        stk.pop_back();

                        if (!f.has_pipe) {
                            bad = true;
                        } else {
                            // reduce this frame into a valid unit
                            if (!stk.empty()) {
                                if (!stk.back().has_pipe)
                                    stk.back().left_ok &= true;
                                else
                                    stk.back().right_ok &= true;
                            }
                        }
                    }
                }
            }
        } else {
            stk = hist_stk.back();
            bad = hist_bad.back();
            hist_stk.pop_back();
            hist_bad.pop_back();

            cout << (!bad && stk.empty() ? "Yes\n" : "No\n");
            continue;
        }

        hist_stk.push_back(stk);
        hist_bad.push_back(bad);

        cout << (!bad && stk.empty() ? "Yes\n" : "No\n");
    }

    return 0;
}
0