結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-04-24 19:56:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 5,000 ms |
コード長 | 703 bytes |
コンパイル時間 | 3,429 ms |
コンパイル使用メモリ | 77,796 KB |
実行使用メモリ | 41,396 KB |
最終ジャッジ日時 | 2024-07-20 07:00:06 |
合計ジャッジ時間 | 5,980 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.util.*;public class Yukicoder_22{public static void main(String[] args){Scanner stdIn = new Scanner(System.in);int N = stdIn.nextInt();int K = stdIn.nextInt();String str = stdIn.next();char par = str.charAt(K-1);if(par == (char)'('){int count = 1;for(int i=K;i<N;i++){if(str.charAt(i) == (char)'('){count++;}else{count--;}if(count == 0){System.out.println(i+1);break;}}}else{int count = 1;for(int i=K-2;i>=0;i--){if(str.charAt(i) == (char)'('){count--;}else{count++;}if(count == 0){System.out.println(i+1);break;}}}}}