結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー さかぽんさかぽん
提出日時 2021-12-19 16:45:32
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 1,375 bytes
コンパイル時間 4,800 ms
コンパイル使用メモリ 108,384 KB
実行使用メモリ 816,956 KB
最終ジャッジ日時 2023-10-13 18:52:06
合計ジャッジ時間 23,267 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
42,344 KB
testcase_01 AC 335 ms
46,728 KB
testcase_02 AC 335 ms
40,660 KB
testcase_03 AC 298 ms
41,892 KB
testcase_04 AC 348 ms
45,144 KB
testcase_05 AC 384 ms
73,080 KB
testcase_06 AC 231 ms
45,428 KB
testcase_07 AC 88 ms
31,000 KB
testcase_08 AC 825 ms
124,068 KB
testcase_09 AC 140 ms
44,400 KB
testcase_10 AC 371 ms
75,380 KB
testcase_11 AC 317 ms
63,804 KB
testcase_12 AC 403 ms
76,260 KB
testcase_13 AC 763 ms
124,456 KB
testcase_14 AC 335 ms
71,140 KB
testcase_15 AC 68 ms
21,880 KB
testcase_16 AC 784 ms
120,616 KB
testcase_17 AC 834 ms
127,708 KB
testcase_18 AC 806 ms
122,428 KB
testcase_19 AC 918 ms
143,664 KB
testcase_20 AC 815 ms
123,032 KB
testcase_21 AC 68 ms
23,912 KB
testcase_22 AC 68 ms
21,884 KB
testcase_23 AC 438 ms
55,348 KB
testcase_24 AC 489 ms
62,916 KB
testcase_25 AC 585 ms
68,120 KB
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 x, int y) 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>());

		for (int qi = 0; qi < qc; qi++)
		{
			var (x, y) = qs[qi];
			if (x > y) qs[qi] = (y, x);

			map[x].Add(qi);
			if (x != y) map[y].Add(qi);
		}

		// 片方が通過したクエリの 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 == qs[qi].x) umap[i].Add(qi);
			}
			else
			{
				var l = st.Pop();
				var pl = st.Peek();

				foreach (var qi in map[i])
					if (i == qs[qi].x) umap[l].Add(qi);

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

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