結果

問題 No.22 括弧の対応
ユーザー omc-testomc-test
提出日時 2016-08-05 17:13:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 720 bytes
コンパイル時間 3,314 ms
コンパイル使用メモリ 71,956 KB
実行使用メモリ 49,868 KB
最終ジャッジ日時 2023-09-27 13:07:26
合計ジャッジ時間 4,382 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,432 KB
testcase_01 AC 38 ms
49,544 KB
testcase_02 AC 38 ms
49,484 KB
testcase_03 AC 46 ms
49,400 KB
testcase_04 AC 45 ms
49,868 KB
testcase_05 AC 43 ms
49,448 KB
testcase_06 AC 45 ms
49,624 KB
testcase_07 AC 45 ms
49,576 KB
testcase_08 AC 45 ms
49,544 KB
testcase_09 AC 43 ms
49,516 KB
testcase_10 AC 50 ms
49,604 KB
testcase_11 AC 46 ms
49,672 KB
testcase_12 AC 45 ms
49,560 KB
testcase_13 AC 47 ms
49,832 KB
testcase_14 AC 42 ms
49,496 KB
testcase_15 AC 49 ms
49,540 KB
testcase_16 AC 49 ms
49,524 KB
testcase_17 AC 40 ms
49,328 KB
testcase_18 AC 39 ms
49,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class No0022 {
	public static void main(String[] args) {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			String str[] = br.readLine().split(" ");
			int n = Integer.parseInt(str[0]);
			int k = Integer.parseInt(str[1]);
			String s = br.readLine();
			int[] ans = new int[n];
			Stack<Integer> st = new Stack<Integer>();
			for(int i=0; i<n; i++){
				if(s.charAt(i)=='('){
					st.add(i+1);
				}else{
					int t = st.pop();
					ans[i]=t;
					ans[t-1]=i+1;				}
			}
			System.out.println(ans[k-1]);
		}catch(IOException e){
			e.printStackTrace();
		}
	}
}
0