結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2017-10-28 17:03:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 155 ms / 5,000 ms |
コード長 | 750 bytes |
コンパイル時間 | 2,453 ms |
コンパイル使用メモリ | 81,352 KB |
実行使用メモリ | 41,896 KB |
最終ジャッジ日時 | 2024-07-20 07:26:57 |
合計ジャッジ時間 | 5,829 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
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); } }