結果

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

ソースコード

diff #
raw source code

function Main(input) {
	input = input.split("\n");

	const N = Number(input.shift());

	const ans = [];

	const stack = [];
	const arr = [];

	for (let i = 0; i < N; 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.push("(");
				stack.push("|");
			} else {
				arr.pop();
			}
		}
		ans.push(stack.length > 0 ? "No" : "Yes");
	}
	console.log(ans.join("\n"));
}
Main(require("fs").readFileSync(0) + "")
0