結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2014-11-01 04:04:32 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 663 bytes |
コンパイル時間 | 2,644 ms |
コンパイル使用メモリ | 74,428 KB |
実行使用メモリ | 41,380 KB |
最終ジャッジ日時 | 2024-07-20 06:54:33 |
合計ジャッジ時間 | 5,020 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Main p = new Main(); } public Main() { Scanner sc = new Scanner(System.in); sc.nextInt(); int n = sc.nextInt()-1; String s =sc.next(); System.out.println(solve(s, n)+1); } public int solve(String s, int n) { int c = 0; if(s.charAt(n)=='('){ for(int i=n;i<s.length();i++){ if(s.charAt(i)=='(') c--; else c++; if(c==0) return i; } }else{ for(int i=n;0<=i;i--){ if(s.charAt(i)==')') c--; else c++; if(c==0) return i; } } return -1; } }