結果

問題 No.22 括弧の対応
ユーザー ぴろずぴろず
提出日時 2014-12-19 11:24:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 71,308 KB
実行使用メモリ 57,876 KB
最終ジャッジ日時 2023-09-27 12:47:29
合計ジャッジ時間 4,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,760 KB
testcase_01 AC 110 ms
53,496 KB
testcase_02 AC 111 ms
55,680 KB
testcase_03 AC 124 ms
55,836 KB
testcase_04 AC 127 ms
56,156 KB
testcase_05 AC 130 ms
56,032 KB
testcase_06 AC 128 ms
56,020 KB
testcase_07 AC 124 ms
55,668 KB
testcase_08 AC 124 ms
55,704 KB
testcase_09 AC 121 ms
55,956 KB
testcase_10 AC 125 ms
55,536 KB
testcase_11 AC 129 ms
55,716 KB
testcase_12 AC 131 ms
57,876 KB
testcase_13 AC 124 ms
55,964 KB
testcase_14 AC 114 ms
55,908 KB
testcase_15 AC 126 ms
55,652 KB
testcase_16 AC 126 ms
55,584 KB
testcase_17 AC 114 ms
55,868 KB
testcase_18 AC 112 ms
56,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no022;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		int nest = 0;
		while(true) {
			if (s.charAt(k-1) == '(') {
				nest++;
			}else{
				nest--;
			}
			if (nest == 0) {
				break;
			}
			if (nest > 0) {
				k++;
			}else{
				k--;
			}
		}
		System.out.println(k);
	}

}
0