結果

問題 No.22 括弧の対応
ユーザー TatsuDXTatsuDX
提出日時 2016-09-08 23:29:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 438 bytes
コンパイル時間 2,719 ms
コンパイル使用メモリ 72,108 KB
実行使用メモリ 56,328 KB
最終ジャッジ日時 2023-09-27 13:08:36
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,308 KB
testcase_01 AC 110 ms
55,860 KB
testcase_02 AC 108 ms
55,924 KB
testcase_03 AC 123 ms
56,068 KB
testcase_04 AC 122 ms
55,864 KB
testcase_05 AC 121 ms
55,816 KB
testcase_06 AC 120 ms
55,916 KB
testcase_07 AC 122 ms
55,548 KB
testcase_08 AC 126 ms
55,984 KB
testcase_09 AC 121 ms
55,980 KB
testcase_10 AC 124 ms
55,832 KB
testcase_11 AC 127 ms
55,872 KB
testcase_12 AC 123 ms
55,812 KB
testcase_13 AC 121 ms
56,196 KB
testcase_14 AC 113 ms
56,328 KB
testcase_15 AC 125 ms
55,856 KB
testcase_16 AC 121 ms
54,020 KB
testcase_17 AC 106 ms
56,168 KB
testcase_18 AC 107 ms
56,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt(), k = sc.nextInt(), idx = 0;
		int[] t = new int[n], st = new int[n];
		String s = sc.next();
		for(int i = 0; i < n; i++){
			if(s.charAt(i) == '('){
				st[idx] = i;
				idx++;
			} else {
				idx--;
				t[i] = st[idx];
				t[st[idx]] = i;
			}
		}
		System.out.println(t[k-1]+1);
	}
}
0