結果

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

ソースコード

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