結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー さかぽんさかぽん
提出日時 2021-12-19 14:06:22
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 1,355 bytes
コンパイル時間 5,331 ms
コンパイル使用メモリ 105,660 KB
実行使用メモリ 856,816 KB
最終ジャッジ日時 2023-10-13 18:44:02
合計ジャッジ時間 24,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 89 ms
28,944 KB
testcase_08 WA -
testcase_09 AC 143 ms
40,388 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 338 ms
71,600 KB
testcase_15 AC 69 ms
21,860 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 72 ms
19,772 KB
testcase_22 AC 68 ms
21,924 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++)
		{
			if (s[i - 1] == '(')
			{
				st.Push(i);

				foreach (var qi in map[i])
					if (i < end[qi]) umap[i].Add(qi);
			}
			else
			{
				var l = st.Pop();
				var pl = st.Peek();

				foreach (var qi in map[i])
					if (i < end[qi]) umap[l].Add(qi);

				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