結果

問題 No.22 括弧の対応
ユーザー kou6839
提出日時 2014-11-16 19:19:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 75,228 KB
実行使用メモリ 41,612 KB
最終ジャッジ日時 2024-07-20 06:55:28
合計ジャッジ時間 4,917 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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