結果

問題 No.22 括弧の対応
ユーザー kou6839kou6839
提出日時 2014-11-16 19:19:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 72,288 KB
実行使用メモリ 56,624 KB
最終ジャッジ日時 2023-09-27 12:46:39
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,456 KB
testcase_01 AC 114 ms
56,068 KB
testcase_02 AC 114 ms
56,076 KB
testcase_03 AC 134 ms
55,724 KB
testcase_04 AC 138 ms
55,876 KB
testcase_05 AC 131 ms
56,624 KB
testcase_06 AC 126 ms
55,740 KB
testcase_07 AC 128 ms
55,912 KB
testcase_08 AC 130 ms
56,132 KB
testcase_09 AC 131 ms
55,716 KB
testcase_10 AC 126 ms
56,296 KB
testcase_11 AC 131 ms
55,896 KB
testcase_12 AC 130 ms
56,272 KB
testcase_13 AC 128 ms
56,104 KB
testcase_14 AC 117 ms
56,016 KB
testcase_15 AC 131 ms
56,072 KB
testcase_16 AC 131 ms
55,888 KB
testcase_17 AC 114 ms
56,032 KB
testcase_18 AC 116 ms
55,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		Stack<Integer> a = new Stack<Integer>();
		for(int i=0;i<n;i++){
			char rr=s.charAt(i);
			if(rr=='('){
				a.add(i+1);
			}else{
				if(i+1==m){
					System.out.println(a.pop());
					return;
				}
				if(a.pop()==m){
					System.out.println(i+1);
					return;
				}
			}
		}
	}
}
0