結果

問題 No.22 括弧の対応
ユーザー UEUEUE66
提出日時 2019-06-15 05:02:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 74,084 KB
実行使用メモリ 41,500 KB
最終ジャッジ日時 2024-07-20 07:43:15
合計ジャッジ時間 5,703 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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