結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-26 12:16:05 |
| 言語 | Java (openjdk 26.0.2.1) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 5,000 ms |
| + 762µs | |
| コード長 | 693 bytes |
| 記録 | |
| コンパイル時間 | 1,811 ms |
| コンパイル使用メモリ | 86,196 KB |
| 実行使用メモリ | 48,180 KB |
| 最終ジャッジ日時 | 2026-08-19 17:43:28 |
| 合計ジャッジ時間 | 5,045 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
package yukicoder.No22;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = Integer.parseInt(sc.next());
int K = Integer.parseInt(sc.next());
String[] S = sc.next().split("");
Map<Integer, Integer> dp = new HashMap<>();
Stack<Integer> stack = new Stack<>();
for (int i = 0; i < N; i++) {
if (S[i].equals("(")) {
stack.push(i);
} else {
int n = stack.pop();
dp.put(i, n);
dp.put(n, i);
}
}
System.out.println(dp.get(K - 1) + 1);
}
}