結果

問題 No.22 括弧の対応
ユーザー shinwisteriashinwisteria
提出日時 2019-01-21 21:40:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 4,206 ms
コンパイル使用メモリ 73,556 KB
実行使用メモリ 58,012 KB
最終ジャッジ日時 2023-09-27 13:33:59
合計ジャッジ時間 7,985 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,960 KB
testcase_01 AC 127 ms
55,284 KB
testcase_02 AC 129 ms
55,668 KB
testcase_03 AC 164 ms
55,636 KB
testcase_04 AC 157 ms
55,632 KB
testcase_05 AC 154 ms
55,928 KB
testcase_06 AC 157 ms
55,744 KB
testcase_07 AC 156 ms
55,752 KB
testcase_08 AC 155 ms
55,944 KB
testcase_09 AC 158 ms
55,980 KB
testcase_10 AC 156 ms
58,012 KB
testcase_11 AC 141 ms
55,708 KB
testcase_12 AC 156 ms
55,816 KB
testcase_13 AC 158 ms
55,752 KB
testcase_14 AC 135 ms
55,976 KB
testcase_15 AC 159 ms
56,084 KB
testcase_16 AC 158 ms
55,796 KB
testcase_17 AC 125 ms
55,832 KB
testcase_18 AC 126 ms
55,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Stack;
public class No22 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt() , K = s.nextInt();
		s.nextLine();
		String St = s.nextLine();
		s.close();
		Stack<Integer> stack = new Stack<>();
		for(int i = 0;i < N;i++){
			if(St.charAt(i) == '('){
				stack.push(i);
			}else{
				if(i + 1 == K){
					System.out.println(stack.pop() + 1);
					break;
				}else if(stack.peek() + 1 == K){
					System.out.println(i + 1);
					break;
				}else{
					stack.pop();
				}
			}
		}

	}

}
0