結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー さかぽんさかぽん
提出日時 2021-12-19 13:55:51
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 5,858 ms
コンパイル使用メモリ 109,568 KB
実行使用メモリ 748,236 KB
最終ジャッジ日時 2023-10-13 18:43:08
合計ジャッジ時間 26,262 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 69 ms
21,820 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 71 ms
21,848 KB
testcase_22 AC 68 ms
21,928 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 MLE -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class G
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var (n, qc) = Read2();
		var s = Console.ReadLine();
		var qs = Array.ConvertAll(new bool[qc], _ => Read2());

		var map = Array.ConvertAll(new bool[n + 1], _ => new List<int>());
		var end = new int[qc];

		for (int qi = 0; qi < qc; qi++)
		{
			var (x, y) = qs[qi];
			map[x].Add(qi);
			map[y].Add(qi);
			end[qi] = Math.Max(x, y);
		}

		// 片方が通過したクエリの ID
		var umap = Array.ConvertAll(map, _ => new List<int>());

		var r = new (int l, int r)[qc];
		var st = new Stack<int>();
		st.Push(0);

		for (int i = 1; i <= n; i++)
		{
			foreach (var qi in map[i])
				if (i < end[qi]) umap[i].Add(qi);

			if (s[i - 1] == '(')
			{
				st.Push(i);
			}
			else
			{
				var l = st.Pop();
				var pl = st.Peek();

				foreach (var qi in umap[l])
				{
					if (end[qi] <= i)
					{
						r[qi] = (l, i);
					}
					else
					{
						umap[pl].Add(qi);
					}
				}
			}
		}

		return string.Join("\n", r.Select(p => p.l == 0 ? "-1" : $"{p.l} {p.r}"));
	}
}
0