結果

問題 No.22 括弧の対応
ユーザー pirorirori_n712pirorirori_n712
提出日時 2018-10-05 02:21:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 1,123 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 103,324 KB
実行使用メモリ 23,964 KB
最終ジャッジ日時 2023-09-27 13:31:08
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
23,896 KB
testcase_01 AC 52 ms
21,884 KB
testcase_02 AC 52 ms
23,872 KB
testcase_03 AC 52 ms
22,056 KB
testcase_04 AC 53 ms
19,800 KB
testcase_05 AC 53 ms
21,852 KB
testcase_06 AC 53 ms
23,828 KB
testcase_07 AC 56 ms
23,780 KB
testcase_08 AC 55 ms
23,964 KB
testcase_09 AC 54 ms
21,732 KB
testcase_10 AC 54 ms
23,752 KB
testcase_11 AC 52 ms
21,824 KB
testcase_12 AC 52 ms
21,928 KB
testcase_13 AC 52 ms
23,912 KB
testcase_14 AC 53 ms
21,988 KB
testcase_15 AC 52 ms
21,780 KB
testcase_16 AC 53 ms
21,992 KB
testcase_17 AC 53 ms
23,892 KB
testcase_18 AC 51 ms
23,880 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;

class No22
{
    static void Main()
    {
        var num = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var line = Console.ReadLine().ToCharArray();
        var isAdd = line[num[1] - 1] == '(' ? true : false;
        var i = isAdd ? 0 : line.Length - 1;
        var firstChar = isAdd ? line[0] : line[line.Length - 1];
        var beforeChar = firstChar;
        var shindo = 1;
        var myShindo = ((isAdd && num[1] == 1) || (!isAdd && num[1] == line.Length)) ? 1 : 0;
        while (true)
        {
            i = isAdd ? i + 1 : i - 1;
            if (line[i] == beforeChar)
            {
                if (line[i] == firstChar) shindo++;
                else shindo--;
            }
            if (i + 1 == num[1]) myShindo = shindo;
            if (isAdd)
            {
                if (shindo == myShindo && line[i] == ')') break;
            }
            else
            {
                if (shindo == myShindo && line[i] == '(') break;
            }
            beforeChar = line[i];
        }
        Console.WriteLine(i + 1);
    }
}
0