結果

問題 No.22 括弧の対応
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-14 01:33:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 71,108 KB
実行使用メモリ 58,180 KB
最終ジャッジ日時 2023-09-27 13:10:15
合計ジャッジ時間 5,268 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,040 KB
testcase_01 AC 112 ms
55,728 KB
testcase_02 AC 110 ms
56,480 KB
testcase_03 AC 156 ms
55,952 KB
testcase_04 AC 143 ms
55,984 KB
testcase_05 AC 141 ms
56,356 KB
testcase_06 AC 151 ms
56,004 KB
testcase_07 AC 164 ms
56,248 KB
testcase_08 AC 143 ms
56,400 KB
testcase_09 AC 147 ms
56,272 KB
testcase_10 AC 151 ms
56,012 KB
testcase_11 AC 145 ms
56,584 KB
testcase_12 AC 147 ms
58,180 KB
testcase_13 AC 151 ms
56,192 KB
testcase_14 AC 139 ms
56,716 KB
testcase_15 AC 155 ms
56,856 KB
testcase_16 AC 156 ms
56,056 KB
testcase_17 AC 111 ms
53,876 KB
testcase_18 AC 111 ms
55,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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();
        String [] arr = S.split("");
        int a=0;
        if( arr[K-1].equals(")") ){
            while(a!=-1){
                K--;
                if( arr[K-1].equals(")") ){
                    a++;
                }else{
                    a--;
                }
            }
        }else{
            while(a!=-1){
                K++;
                if( arr[K-1].equals("(") ){
                    a++;
                }else{
                    a--;
                }
            }
        }
        System.out.println(K);
    }
}
0