結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2016-07-09 20:17:13 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 172 ms / 5,000 ms |
コード長 | 482 bytes |
コンパイル時間 | 2,867 ms |
コンパイル使用メモリ | 74,596 KB |
実行使用メモリ | 41,844 KB |
最終ジャッジ日時 | 2024-07-20 07:14:28 |
合計ジャッジ時間 | 6,293 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
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]);}}}