結果

問題 No.1778 括弧列クエリ / Bracketed Sequence Query
ユーザー さかぽんさかぽん
提出日時 2021-12-19 14:15:02
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,369 bytes
コンパイル時間 4,632 ms
コンパイル使用メモリ 106,180 KB
実行使用メモリ 817,216 KB
最終ジャッジ日時 2023-10-13 18:44:42
合計ジャッジ時間 24,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 339 ms
44,088 KB
testcase_01 AC 342 ms
45,448 KB
testcase_02 AC 339 ms
43,008 KB
testcase_03 WA -
testcase_04 AC 350 ms
48,716 KB
testcase_05 AC 394 ms
76,340 KB
testcase_06 AC 240 ms
47,764 KB
testcase_07 AC 89 ms
28,840 KB
testcase_08 AC 855 ms
125,440 KB
testcase_09 AC 142 ms
42,288 KB
testcase_10 AC 382 ms
75,956 KB
testcase_11 AC 329 ms
68,280 KB
testcase_12 AC 416 ms
77,876 KB
testcase_13 AC 789 ms
126,572 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 822 ms
120,568 KB
testcase_17 AC 920 ms
127,700 KB
testcase_18 WA -
testcase_19 AC 933 ms
148,164 KB
testcase_20 WA -
testcase_21 AC 70 ms
21,860 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 635 ms
74,272 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, 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);
			if (x != y) 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