結果

問題 No.22 括弧の対応
ユーザー akichiakichi
提出日時 2017-08-18 23:41:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 100,848 KB
実行使用メモリ 23,972 KB
最終ジャッジ日時 2023-09-27 13:18:49
合計ジャッジ時間 3,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
23,868 KB
testcase_01 AC 56 ms
21,808 KB
testcase_02 AC 56 ms
21,828 KB
testcase_03 AC 56 ms
23,872 KB
testcase_04 AC 56 ms
19,900 KB
testcase_05 AC 59 ms
21,948 KB
testcase_06 AC 59 ms
23,788 KB
testcase_07 AC 56 ms
21,916 KB
testcase_08 AC 55 ms
21,820 KB
testcase_09 AC 56 ms
19,980 KB
testcase_10 AC 54 ms
21,848 KB
testcase_11 AC 54 ms
23,888 KB
testcase_12 AC 56 ms
21,768 KB
testcase_13 AC 56 ms
23,972 KB
testcase_14 AC 56 ms
21,932 KB
testcase_15 AC 54 ms
21,928 KB
testcase_16 AC 55 ms
21,912 KB
testcase_17 AC 53 ms
21,916 KB
testcase_18 AC 53 ms
23,876 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 Program {
    static void Main() {
        int ans;
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nk[0];
        int k = nk[1];
        string s = Console.ReadLine();
        int p = k - 1;
        int dir = s[p] == '(' ? 1 : -1;
        int level = dir;
        
        for (p += dir; ; p += dir) {
            if (s[p] == '(') level++;
            else level--;
            if (level == 0) {
                ans = p + 1;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}
0