結果

問題 No.22 括弧の対応
ユーザー UEUEUE66UEUEUE66
提出日時 2019-06-15 05:02:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 71,904 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-09-27 13:38:47
合計ジャッジ時間 5,707 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
55,684 KB
testcase_01 AC 109 ms
55,852 KB
testcase_02 AC 115 ms
55,792 KB
testcase_03 AC 125 ms
55,892 KB
testcase_04 AC 121 ms
56,052 KB
testcase_05 AC 118 ms
55,668 KB
testcase_06 AC 122 ms
56,036 KB
testcase_07 AC 122 ms
56,192 KB
testcase_08 AC 117 ms
55,948 KB
testcase_09 AC 117 ms
55,688 KB
testcase_10 AC 117 ms
55,480 KB
testcase_11 AC 116 ms
55,764 KB
testcase_12 AC 119 ms
55,888 KB
testcase_13 AC 120 ms
55,920 KB
testcase_14 AC 111 ms
55,636 KB
testcase_15 AC 120 ms
55,812 KB
testcase_16 AC 127 ms
55,812 KB
testcase_17 AC 110 ms
55,644 KB
testcase_18 AC 107 ms
55,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        sc.close();

        int count = 0;
        while (true) {
            if (s.charAt(k-1) == '(') count++;
            else count--;

            if (count > 0) k++;
            else if (count < 0) k--;
            else break;
        }

        System.out.println(k);
    }
}
0