結果

問題 No.3503 Brackets Stack Query 2
コンテスト
ユーザー Atake-MKU
提出日時 2026-04-19 13:39:02
言語 JavaScript
(node v25.8.2)
コンパイル:
true
実行:
node _filename_ ONLINE_JUDGE
結果
WA  
実行時間 -
コード長 950 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 348 ms
コンパイル使用メモリ 6,784 KB
実行使用メモリ 186,364 KB
最終ジャッジ日時 2026-04-19 13:39:30
合計ジャッジ時間 18,447 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

function Main(input) {
    input = input.split("\n");
    const Q = Number(input.shift());
    
    const stack = [];
    const arr = [];
    const ans = [];

    for (let i = 0; i < Q; i++) {
        const [q, c] = input[i].trim().split(" ");
        
        if (q === "1") {
            stack.push(c);
            arr.push(c);

            const l = stack.length;
            
            if (l > 2) {
                if (stack[l - 3] + stack[l - 2] + stack[l - 1] == "(|)") {
                    for (let i = 0; i < 3; i++, stack.pop());
                }
            }
        } else {
            if (arr.at(-1) === ")" && stack.at(-1) !== ")") {
                stack.push("(");
                stack.push("|");
            } else {
                stack.pop();
            }
            arr.pop();
        }

        ans.push(stack.length === 0 ? "Yes" : "No");
    }

    console.log(ans.join("\n"));
}
Main(require("fs").readFileSync(0)+"")
0