結果

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

ソースコード

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();
		}
		console.log(stack.length > 0 ? "No" : "Yes");
	}
}
Main(require("fs").readFileSync(0) + "")
0