結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー 沖田誠悟
提出日時 2026-04-18 12:50:17
言語 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  
実行時間 -
コード長 1,508 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,624 ms
コンパイル使用メモリ 338,108 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2026-04-18 12:50:48
合計ジャッジ時間 27,535 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uns= unsigned long long;
#define rep(i,a,b) for(ll i = (a); i < (b); i++)

int main() {
    stack<int> s0,s1,s2,sok;
    s0.push(0);
    s1.push(0);
    s2.push(0);
    sok.push(1);
    int Q;
    cin>>Q;
    rep(i,0,Q){
        int q;
        cin>>q;
        if(q==1){
            char S;
            cin>>S;
            
            if(S=='('){
            s0.push(s0.top()+1);
            s1.push(s1.top());
            s2.push(s2.top());
            }
            if(S=='|'){
            s0.push(s0.top());
            s1.push(s1.top()+1);
            s2.push(s2.top());
            }
            if(S==')'){
            s0.push(s0.top());
            s1.push(s1.top());
            s2.push(s2.top()+1);
            }
            if(sok.top()&&s0.top()>=s1.top()&&s1.top()>=s2.top()&&s1.top()<s2.top()+2){
                sok.push(1);
            }
            else{
                sok.push(0);
            }
            if(sok.top()==1&&s0.top()==s1.top()&&s1.top()==s2.top()){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
            
    
        }
        else{
            s0.pop();
            s1.pop();
            s2.pop();
            sok.pop();
            if(sok.top()==1&&s0.top()==s1.top()&&s1.top()==s2.top()){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }


    }
}
0