結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー さかぽんさかぽん
提出日時 2021-12-19 16:29:46
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 1,354 bytes
コンパイル時間 3,498 ms
コンパイル使用メモリ 108,192 KB
実行使用メモリ 861,944 KB
最終ジャッジ日時 2023-10-13 18:50:34
合計ジャッジ時間 24,104 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 332 ms
44,772 KB
testcase_02 AC 339 ms
40,652 KB
testcase_03 AC 299 ms
43,920 KB
testcase_04 AC 346 ms
45,272 KB
testcase_05 AC 388 ms
72,868 KB
testcase_06 AC 230 ms
47,408 KB
testcase_07 AC 87 ms
31,208 KB
testcase_08 AC 829 ms
124,148 KB
testcase_09 AC 139 ms
40,408 KB
testcase_10 AC 370 ms
77,356 KB
testcase_11 AC 318 ms
67,736 KB
testcase_12 AC 407 ms
74,036 KB
testcase_13 AC 761 ms
124,500 KB
testcase_14 AC 331 ms
71,280 KB
testcase_15 AC 68 ms
21,824 KB
testcase_16 AC 787 ms
120,688 KB
testcase_17 AC 834 ms
125,524 KB
testcase_18 AC 812 ms
120,352 KB
testcase_19 AC 917 ms
147,888 KB
testcase_20 AC 840 ms
122,900 KB
testcase_21 AC 69 ms
22,064 KB
testcase_22 AC 70 ms
23,920 KB
testcase_23 AC 474 ms
57,244 KB
testcase_24 AC 508 ms
62,860 KB
testcase_25 AC 606 ms
66,092 KB
testcase_26 TLE -
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);
					}
				}
			}
		}

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