結果

問題 No.22 括弧の対応
ユーザー mits58mits58
提出日時 2016-07-09 20:17:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 482 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 72,288 KB
実行使用メモリ 56,404 KB
最終ジャッジ日時 2023-09-27 13:06:55
合計ジャッジ時間 5,653 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,916 KB
testcase_01 AC 125 ms
55,936 KB
testcase_02 AC 127 ms
56,132 KB
testcase_03 AC 147 ms
55,596 KB
testcase_04 AC 144 ms
56,100 KB
testcase_05 AC 144 ms
55,884 KB
testcase_06 AC 144 ms
56,040 KB
testcase_07 AC 145 ms
55,456 KB
testcase_08 AC 144 ms
56,404 KB
testcase_09 AC 141 ms
55,816 KB
testcase_10 AC 140 ms
55,928 KB
testcase_11 AC 141 ms
55,856 KB
testcase_12 AC 144 ms
55,944 KB
testcase_13 AC 145 ms
55,888 KB
testcase_14 AC 135 ms
56,000 KB
testcase_15 AC 147 ms
55,732 KB
testcase_16 AC 144 ms
56,192 KB
testcase_17 AC 125 ms
55,452 KB
testcase_18 AC 128 ms
55,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int k=sc.nextInt();
			String s=sc.next();
			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]);
		}
	}
}
0