結果

問題 No.22 括弧の対応
ユーザー suiginginsuigingin
提出日時 2015-07-07 02:00:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 525 bytes
コンパイル時間 3,902 ms
コンパイル使用メモリ 72,928 KB
実行使用メモリ 56,352 KB
最終ジャッジ日時 2023-09-27 12:55:27
合計ジャッジ時間 6,306 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,820 KB
testcase_01 AC 112 ms
56,004 KB
testcase_02 AC 113 ms
56,220 KB
testcase_03 AC 130 ms
55,752 KB
testcase_04 AC 127 ms
55,784 KB
testcase_05 AC 130 ms
56,068 KB
testcase_06 AC 129 ms
55,744 KB
testcase_07 AC 125 ms
55,800 KB
testcase_08 AC 127 ms
56,352 KB
testcase_09 AC 126 ms
55,684 KB
testcase_10 AC 124 ms
55,692 KB
testcase_11 AC 124 ms
55,740 KB
testcase_12 AC 128 ms
55,760 KB
testcase_13 AC 128 ms
56,028 KB
testcase_14 AC 121 ms
55,508 KB
testcase_15 AC 134 ms
55,992 KB
testcase_16 AC 132 ms
56,228 KB
testcase_17 AC 112 ms
55,908 KB
testcase_18 AC 115 ms
55,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Stack;

public class No_022 {
	Scanner sc = new Scanner(System.in);

	void run() {
		int N = sc.nextInt();
		int K = sc.nextInt();
		String s = sc.next();
		Stack<Integer> stack = new Stack<>();
		for (int i = 0; i < N; i++) {
			if (s.charAt(i) == '(') stack.add(i + 1);
			else {
				int num = stack.pop();
				if ((i + 1) == K) System.out.println(num);
				if (num == K) System.out.println(i + 1);
			}
		}
	}

	public static void main(String[] args) {
		new No_022().run();
	}
}
0