結果

問題 No.22 括弧の対応
ユーザー abL8ZLsTbFabL8ZLsTbF
提出日時 2016-08-20 23:44:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 713 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 106,008 KB
実行使用メモリ 23,976 KB
最終ジャッジ日時 2023-09-27 13:07:54
合計ジャッジ時間 4,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,976 KB
testcase_01 AC 61 ms
21,832 KB
testcase_02 AC 61 ms
22,000 KB
testcase_03 AC 61 ms
21,840 KB
testcase_04 AC 62 ms
21,940 KB
testcase_05 AC 62 ms
23,968 KB
testcase_06 AC 62 ms
21,808 KB
testcase_07 AC 61 ms
21,920 KB
testcase_08 AC 61 ms
21,872 KB
testcase_09 AC 61 ms
21,744 KB
testcase_10 AC 62 ms
21,812 KB
testcase_11 AC 61 ms
22,080 KB
testcase_12 AC 61 ms
19,708 KB
testcase_13 AC 62 ms
21,864 KB
testcase_14 AC 61 ms
19,840 KB
testcase_15 AC 62 ms
21,844 KB
testcase_16 AC 62 ms
21,892 KB
testcase_17 AC 61 ms
21,852 KB
testcase_18 AC 61 ms
21,844 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

public class Test
{
	public static void Main()
	{
		int[] NK = Console.ReadLine().Split().Select(i => int.Parse(i))
			.ToArray();
		int N = NK[0];
		int K = NK[1] - 1;
		string S = Console.ReadLine();
		if (S[K] == '(')
		{
			int attr = 1;
			for (int i = K + 1; i < S.Length; i++)
			{
				if (S[i] == '(')
				{
					attr++;
				}
				else
				{
					if (--attr == 0)
					{
						Console.WriteLine(i + 1);
						return;
					}
				}
			}
		}
		else
		{
			int attr = -1;
			for (int i = K - 1; i >= 0; i--)
			{
				if (S[i] == ')')
				{
					attr--;
				}
				else
				{
					if (++attr == 0)
					{
						Console.WriteLine(i + 1);
						return;
					}
				}
			}
		}
	}
}
0