結果

問題 No.22 括弧の対応
ユーザー AoiroFukurouAoiroFukurou
提出日時 2016-05-22 16:49:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 3,933 ms
コンパイル使用メモリ 77,192 KB
実行使用メモリ 41,844 KB
最終ジャッジ日時 2024-04-16 06:48:23
合計ジャッジ時間 7,254 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
40,972 KB
testcase_01 AC 133 ms
41,276 KB
testcase_02 AC 120 ms
40,096 KB
testcase_03 AC 174 ms
41,320 KB
testcase_04 AC 167 ms
41,224 KB
testcase_05 AC 163 ms
41,356 KB
testcase_06 AC 163 ms
41,304 KB
testcase_07 WA -
testcase_08 AC 158 ms
41,520 KB
testcase_09 WA -
testcase_10 AC 168 ms
41,404 KB
testcase_11 AC 150 ms
41,384 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 150 ms
40,916 KB
testcase_16 AC 186 ms
41,736 KB
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

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();
		sc.nextLine();
		String S = sc.nextLine();
		sc.close();
		int c = 1;
		String str = S.substring(K - 1, K);
		if (str.equals("(")) {
			while (true) {
				str = S.substring(K, K + 1);
				if (c == 0) {
					System.out.println(K);
					break;
				} else if (str.equals("(")) {
					c++;
					K++;
				} else if (str.equals(")")) {
					c--;
					K++;
				}
			}
		} else if (str.equals(")")) {
			int K2 = K - 1;
			while (true) {
				if(K2==0){
				str = S.substring(K2,K2 + 1);
				System.out.println(1);
				break;
				}
				if (c == 0) {
					System.out.println(K2 + 1);
					break;
				}else if (str.equals(")")) {
					c++;
					K2--;
				} else if (str.equals("(")) {
					c--;
					K2--;
				}
			}
		}
	}
}
0