結果

問題 No.22 括弧の対応
ユーザー TrimozGitTrimozGit
提出日時 2017-09-05 17:23:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 855 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 104,948 KB
実行使用メモリ 23,948 KB
最終ジャッジ日時 2023-09-27 13:19:03
合計ジャッジ時間 4,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
21,776 KB
testcase_01 AC 55 ms
21,832 KB
testcase_02 AC 57 ms
23,824 KB
testcase_03 AC 69 ms
23,948 KB
testcase_04 AC 60 ms
21,900 KB
testcase_05 AC 56 ms
23,712 KB
testcase_06 AC 57 ms
21,752 KB
testcase_07 AC 59 ms
21,792 KB
testcase_08 AC 61 ms
21,892 KB
testcase_09 AC 58 ms
19,788 KB
testcase_10 AC 59 ms
23,904 KB
testcase_11 AC 57 ms
21,876 KB
testcase_12 AC 60 ms
19,932 KB
testcase_13 AC 60 ms
21,840 KB
testcase_14 AC 59 ms
23,872 KB
testcase_15 AC 59 ms
21,896 KB
testcase_16 AC 59 ms
21,864 KB
testcase_17 AC 56 ms
23,840 KB
testcase_18 AC 57 ms
21,820 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yukicorder22
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] N = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
			char[] line = Console.ReadLine().ToCharArray();
			int[] table = new int[N[0]];

			int cnt = 1;
			for (var i = 0; i < N[0]; i++)
			{
				var kakko = 1;
				var j = i + 1;
				while (table[i] == 0 &&  kakko != 0 && i < N[0] - 1)
				{
					if (line[j] == ')') kakko--;
					if (line[j] == '(') kakko++;
					if(kakko == 0)
					{
						table[i] = j + 1;
						table[j] = i + 1;
						cnt++;
						break;
					} else
					{
						j++;
					}
				}
			}
			//			Console.WriteLine(string.Join(" ",table));
			Console.WriteLine(table[N[1] -1]);
			Console.ReadKey();
		}
	}
}
0