結果

問題 No.22 括弧の対応
ユーザー Mcpu3Mcpu3
提出日時 2018-08-28 21:02:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 454 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 71,708 KB
実行使用メモリ 56,452 KB
最終ジャッジ日時 2023-09-27 13:29:56
合計ジャッジ時間 6,062 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
55,844 KB
testcase_01 AC 108 ms
56,452 KB
testcase_02 AC 109 ms
55,764 KB
testcase_03 AC 124 ms
55,948 KB
testcase_04 AC 120 ms
55,864 KB
testcase_05 AC 118 ms
55,840 KB
testcase_06 AC 121 ms
55,852 KB
testcase_07 AC 121 ms
55,952 KB
testcase_08 AC 119 ms
56,000 KB
testcase_09 AC 118 ms
55,804 KB
testcase_10 AC 119 ms
55,472 KB
testcase_11 AC 118 ms
55,372 KB
testcase_12 AC 120 ms
55,752 KB
testcase_13 AC 119 ms
55,724 KB
testcase_14 AC 110 ms
55,928 KB
testcase_15 AC 121 ms
55,980 KB
testcase_16 AC 119 ms
55,800 KB
testcase_17 AC 106 ms
55,764 KB
testcase_18 AC 103 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt(),f=0,b=0,i;
		String s=sc.next();
		sc.close();
		if(s.charAt(k-1)==')') {
			for(i=k-2;f-b!=1;i--) {
				if(s.charAt(i)==')') b++;
				else f++;
			}
			i+=2;
		}
		else {
			for(i=k;b-f!=1;i++) {
				if(s.charAt(i)=='(') f++;
				else b++;
			}
		}
		System.out.print(i);
	}
}
0