結果

問題 No.22 括弧の対応
ユーザー itezpaceitezpace
提出日時 2016-08-18 12:32:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 972 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 73,556 KB
実行使用メモリ 49,592 KB
最終ジャッジ日時 2023-09-27 13:07:46
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,364 KB
testcase_01 AC 39 ms
49,180 KB
testcase_02 AC 40 ms
49,252 KB
testcase_03 AC 39 ms
49,436 KB
testcase_04 AC 40 ms
49,400 KB
testcase_05 AC 39 ms
49,356 KB
testcase_06 AC 39 ms
49,592 KB
testcase_07 AC 39 ms
49,392 KB
testcase_08 AC 40 ms
49,472 KB
testcase_09 AC 38 ms
49,320 KB
testcase_10 AC 40 ms
49,388 KB
testcase_11 AC 38 ms
49,248 KB
testcase_12 AC 39 ms
49,328 KB
testcase_13 AC 39 ms
49,304 KB
testcase_14 AC 39 ms
49,420 KB
testcase_15 AC 42 ms
49,448 KB
testcase_16 AC 41 ms
49,304 KB
testcase_17 AC 38 ms
49,208 KB
testcase_18 AC 39 ms
49,456 KB
権限があれば一括ダウンロードができます

ソースコード

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