結果

問題 No.22 括弧の対応
ユーザー soujikisoujiki
提出日時 2015-04-24 19:56:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 144 ms / 5,000 ms
コード長 703 bytes
コンパイル時間 4,027 ms
コンパイル使用メモリ 72,268 KB
実行使用メモリ 56,432 KB
最終ジャッジ日時 2023-09-27 12:52:26
合計ジャッジ時間 7,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,920 KB
testcase_01 AC 132 ms
55,696 KB
testcase_02 AC 129 ms
55,844 KB
testcase_03 AC 143 ms
55,696 KB
testcase_04 AC 139 ms
55,984 KB
testcase_05 AC 142 ms
55,560 KB
testcase_06 AC 141 ms
55,736 KB
testcase_07 AC 142 ms
56,432 KB
testcase_08 AC 142 ms
56,088 KB
testcase_09 AC 141 ms
55,736 KB
testcase_10 AC 142 ms
55,712 KB
testcase_11 AC 139 ms
55,784 KB
testcase_12 AC 141 ms
56,024 KB
testcase_13 AC 142 ms
55,840 KB
testcase_14 AC 131 ms
56,064 KB
testcase_15 AC 143 ms
56,196 KB
testcase_16 AC 144 ms
55,920 KB
testcase_17 AC 126 ms
56,224 KB
testcase_18 AC 127 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Yukicoder_22{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		String str = stdIn.next();

		char par = str.charAt(K-1);

		if(par == (char)'('){
			int count = 1;
			for(int i=K;i<N;i++){
				if(str.charAt(i) == (char)'('){
					count++;
				}
				else{
					count--;
				}

				if(count == 0){
					System.out.println(i+1);
					break;
				}
			}
		}
		else{
			int count = 1;
			for(int i=K-2;i>=0;i--){
				if(str.charAt(i) == (char)'('){
					count--;
				}
				else{
					count++;
				}

				if(count == 0){
					System.out.println(i+1);
					break;
				}
			}

		}



	}
}
0