結果

問題 No.22 括弧の対応
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-14 20:27:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 500 bytes
コンパイル時間 3,162 ms
コンパイル使用メモリ 72,604 KB
実行使用メモリ 56,868 KB
最終ジャッジ日時 2023-09-27 13:24:24
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,584 KB
testcase_01 AC 113 ms
55,988 KB
testcase_02 AC 114 ms
54,500 KB
testcase_03 AC 160 ms
56,300 KB
testcase_04 AC 149 ms
56,080 KB
testcase_05 AC 149 ms
55,756 KB
testcase_06 AC 156 ms
56,096 KB
testcase_07 AC 161 ms
56,408 KB
testcase_08 AC 155 ms
56,324 KB
testcase_09 AC 146 ms
56,124 KB
testcase_10 AC 154 ms
56,196 KB
testcase_11 AC 151 ms
56,600 KB
testcase_12 AC 155 ms
56,340 KB
testcase_13 AC 162 ms
56,640 KB
testcase_14 AC 147 ms
55,852 KB
testcase_15 AC 159 ms
56,868 KB
testcase_16 AC 162 ms
56,316 KB
testcase_17 AC 115 ms
55,840 KB
testcase_18 AC 116 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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