結果

問題 No.22 括弧の対応
ユーザー ゴリポン先生ゴリポン先生
提出日時 2024-01-24 09:59:21
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 566 bytes
コンパイル時間 5,102 ms
コンパイル使用メモリ 200,032 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-24 09:59:28
合計ジャッジ時間 6,722 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

module main;

import std;

void main()
{
	// 入力
	int N, K;
	readln.chomp.formattedRead("%d %d", N, K);
	auto S = readln.chomp;
	// 答えの計算と出力
	int[][] groups;
	auto stack = DList!int();
	foreach (e; S.enumerate(1)) {
		int i = e.index;
		auto c = e.value;
		if (c == '(') {
			stack.insertBack(i);
		} else {
			groups ~= [i, stack.back];
			stack.removeBack;
		}
	}
	// Kが含まれる組を見つける
	auto ans = groups.find!(a => !a.find(K).empty);
	// その組のKでない数を表示する
	writeln(ans.front.find!(a => a != K).front);
}
0