結果

問題 No.22 括弧の対応
ユーザー papipenpapipen
提出日時 2017-04-06 17:14:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 685 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 71,772 KB
実行使用メモリ 56,044 KB
最終ジャッジ日時 2023-09-27 13:13:21
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,372 KB
testcase_01 AC 125 ms
55,516 KB
testcase_02 AC 124 ms
55,848 KB
testcase_03 AC 139 ms
55,472 KB
testcase_04 AC 139 ms
55,908 KB
testcase_05 AC 139 ms
55,368 KB
testcase_06 AC 138 ms
55,708 KB
testcase_07 AC 140 ms
55,660 KB
testcase_08 AC 138 ms
55,468 KB
testcase_09 AC 138 ms
55,656 KB
testcase_10 AC 140 ms
55,720 KB
testcase_11 AC 138 ms
55,408 KB
testcase_12 AC 139 ms
55,784 KB
testcase_13 AC 141 ms
55,396 KB
testcase_14 AC 130 ms
55,552 KB
testcase_15 AC 142 ms
56,044 KB
testcase_16 AC 141 ms
56,012 KB
testcase_17 AC 123 ms
55,496 KB
testcase_18 AC 127 ms
55,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Kakko{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int k = s.nextInt();
		String str = s.next();
		int count = 0;
		
		if(str.charAt(k - 1) == '('){
			for(int i = k; i < n; i++){
				char a = str.charAt(i);
				if(a == '('){
					count++;
				}else{
					count--;
				}
				if(count == -1){
					System.out.println(i + 1);
					System.exit(0);
				}
			}
		}else{
			for(int i = k - 2; i >= 0; i--){
				char a = str.charAt(i);
				if(a == ')'){
					count++;
				}else{
					count--;
				}        
				if(count == -1){
					System.out.println(i + 1);
					System.exit(0);
				}
			}
		}
	}
}
0