結果

問題 No.22 括弧の対応
ユーザー itezpace
提出日時 2016-08-18 12:32:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 972 bytes
コンパイル時間 2,831 ms
コンパイル使用メモリ 77,168 KB
実行使用メモリ 36,908 KB
最終ジャッジ日時 2024-07-20 07:15:32
合計ジャッジ時間 4,806 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

class Yuki22 {
  public static void main(String[] args) throws IOException {
    InputStreamReader is = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(is);
    String s = br.readLine();
    int n,k;
    String[] sa = s.split(" ");
    n = Integer.parseInt(sa[0]);
    k = Integer.parseInt(sa[1]);
    String s2 = br.readLine();
    int x;
    x=s2.length()+1;
    if(s2.charAt(k-1)=='('){
      int a;
      a=1;
      for(int i=k; i<s2.length(); ++i){
        if(s2.charAt(i)=='('){
          a++;
        } else {
          a--;
          if(a==0){
            x=i;
            break;
          }
        }
      }
    } else if(s2.charAt(k-1)==')'){
      int a;
      a=1;
      for(int i=k-2; i>=0; --i){
        if(s2.charAt(i)==')'){
          a++;
        } else {
          a--;
          if(a==0){
            x=i;
            break;
          }
        }
      }
    }
    x+=1;
    System.out.println(x);
  }
}
0