結果

問題 No.22 括弧の対応
ユーザー HimatsubushinHimatsubushin
提出日時 2019-01-04 14:28:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 1,095 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 104,668 KB
実行使用メモリ 22,704 KB
最終ジャッジ日時 2023-09-27 13:32:42
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
20,828 KB
testcase_01 AC 52 ms
20,672 KB
testcase_02 AC 50 ms
20,676 KB
testcase_03 AC 51 ms
20,688 KB
testcase_04 AC 52 ms
20,720 KB
testcase_05 AC 55 ms
20,672 KB
testcase_06 AC 55 ms
22,692 KB
testcase_07 AC 53 ms
22,648 KB
testcase_08 AC 53 ms
20,668 KB
testcase_09 AC 54 ms
22,704 KB
testcase_10 AC 53 ms
20,656 KB
testcase_11 AC 54 ms
22,696 KB
testcase_12 AC 55 ms
20,624 KB
testcase_13 AC 55 ms
20,616 KB
testcase_14 AC 52 ms
18,756 KB
testcase_15 AC 53 ms
20,700 KB
testcase_16 AC 51 ms
22,620 KB
testcase_17 AC 50 ms
20,664 KB
testcase_18 AC 51 ms
20,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace No022_括弧の対応
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            string s = "(" + Console.ReadLine() + ")";
            int count, level = 0;

            if (s[k] == '(')
            {
                count = k - 1;
                do
                {
                    count++;
                    if (s[count] == '(')
                        level++;
                    else
                        level--;
                } while (level > 0 || s[count] != ')');
            }
            else
            {
                count = k + 1;
                do
                {
                    count--;
                    if (s[count] == ')')
                        level++;
                    else
                        level--;
                } while (level > 0 || s[count] != '(');
            }

            Console.WriteLine(count.ToString());
        }
    }
}
0