結果

問題 No.22 括弧の対応
ユーザー uafr_csuafr_cs
提出日時 2017-10-28 17:03:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 750 bytes
コンパイル時間 2,866 ms
コンパイル使用メモリ 71,936 KB
実行使用メモリ 57,332 KB
最終ジャッジ日時 2023-09-27 13:20:46
合計ジャッジ時間 5,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,728 KB
testcase_01 AC 115 ms
55,744 KB
testcase_02 AC 114 ms
55,620 KB
testcase_03 AC 133 ms
55,748 KB
testcase_04 AC 133 ms
55,924 KB
testcase_05 AC 134 ms
56,176 KB
testcase_06 AC 130 ms
55,992 KB
testcase_07 AC 131 ms
55,616 KB
testcase_08 AC 128 ms
56,100 KB
testcase_09 AC 132 ms
55,896 KB
testcase_10 AC 135 ms
55,616 KB
testcase_11 AC 130 ms
56,260 KB
testcase_12 AC 131 ms
55,708 KB
testcase_13 AC 129 ms
55,756 KB
testcase_14 AC 119 ms
55,588 KB
testcase_15 AC 129 ms
55,628 KB
testcase_16 AC 135 ms
55,880 KB
testcase_17 AC 115 ms
57,332 KB
testcase_18 AC 117 ms
55,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt() - 1;
		
		final char[] inputs = sc.next().toCharArray();
		
		int[] trans = new int[N];
		Arrays.fill(trans, -1);
		
		LinkedList<Integer> open_stack = new LinkedList<Integer>();
		for(int index = 0; index < N; index++){
			if(inputs[index] == '('){
				open_stack.addFirst(index);
			}else{
				final int open_index = open_stack.removeFirst();
				
				trans[open_index] = index;
				trans[index] = open_index;
			}
		}
		
		System.out.println(trans[K] + 1);
	}
}
0