結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー dayo ZOI
提出日時 2026-04-18 21:30:53
言語 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
結果
RE  
実行時間 -
コード長 1,555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,933 ms
コンパイル使用メモリ 180,012 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2026-04-18 21:31:50
合計ジャッジ時間 24,212 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 8 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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)
int main() {
    stack<ll> loc;
    loc.emplace(1);

    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 == '(') {
                loc.emplace(loc.top() * 2);
            } else if(c == '|') {
                if(loc.top() % 2 == 1) {
                    error = len;
                    cout << "No" << endl;
                    continue;
                } else {
                    loc.emplace(loc.top() + 1);
                }
            } else {
                if(loc.top() % 2 == 0) {
                    error = len;
                    cout << "No" << endl;
                    continue;
                } else {
                    loc.emplace(loc.top() / 2);
                }
            }
        }
        else {
            len--;
            if(len < error) {
                cout << "No" << endl;
                continue;
            }
            else if(len == error) {
                error = -1;
            } else {
                loc.pop();
            }
        }
        if(loc.top() == 1) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
}
0