結果

問題 No.22 括弧の対応
ユーザー tsunabittsunabit
提出日時 2018-08-05 04:00:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 5,000 ms
コード長 590 bytes
コンパイル時間 3,623 ms
コンパイル使用メモリ 74,036 KB
実行使用メモリ 56,436 KB
最終ジャッジ日時 2023-09-27 13:29:18
合計ジャッジ時間 7,537 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,596 KB
testcase_01 AC 125 ms
55,988 KB
testcase_02 AC 126 ms
55,564 KB
testcase_03 AC 173 ms
56,008 KB
testcase_04 AC 166 ms
56,436 KB
testcase_05 AC 166 ms
56,024 KB
testcase_06 AC 166 ms
56,324 KB
testcase_07 AC 179 ms
56,384 KB
testcase_08 AC 171 ms
56,084 KB
testcase_09 AC 167 ms
56,284 KB
testcase_10 AC 176 ms
56,272 KB
testcase_11 AC 167 ms
56,068 KB
testcase_12 AC 167 ms
56,352 KB
testcase_13 AC 163 ms
56,148 KB
testcase_14 AC 149 ms
56,084 KB
testcase_15 AC 164 ms
56,404 KB
testcase_16 AC 164 ms
56,104 KB
testcase_17 AC 123 ms
56,016 KB
testcase_18 AC 127 ms
55,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.Stream;
import java.time.*;
import java.time.format.*;

public class No22 {
    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 str[] = S.split("");
		int count = 0;
		int i = K - 1;
		while(true) {
			if(str[i].equals("(")){
				count++;
			}else {
				count--;
			}
			
			if(count == 0) {
				break;
			}
			
			if(str[K - 1].equals("(")) {
				i++;
			}else {
				i--;
			}
		}
		
		System.out.println(i + 1);
    }
}
0