結果

問題 No.22 括弧の対応
ユーザー mustonmuston
提出日時 2016-05-11 10:30:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 675 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 71,100 KB
実行使用メモリ 58,328 KB
最終ジャッジ日時 2023-09-27 13:05:15
合計ジャッジ時間 4,847 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,028 KB
testcase_01 AC 106 ms
54,300 KB
testcase_02 AC 108 ms
56,220 KB
testcase_03 AC 122 ms
56,196 KB
testcase_04 AC 121 ms
58,328 KB
testcase_05 AC 124 ms
56,036 KB
testcase_06 AC 121 ms
56,064 KB
testcase_07 AC 121 ms
55,860 KB
testcase_08 AC 121 ms
56,048 KB
testcase_09 AC 120 ms
55,816 KB
testcase_10 AC 123 ms
56,000 KB
testcase_11 AC 120 ms
56,256 KB
testcase_12 AC 120 ms
55,944 KB
testcase_13 AC 122 ms
56,136 KB
testcase_14 AC 113 ms
56,068 KB
testcase_15 AC 127 ms
55,936 KB
testcase_16 AC 119 ms
56,008 KB
testcase_17 AC 107 ms
56,104 KB
testcase_18 AC 106 ms
55,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
class Aaf {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt()-1;
    int ans = 0 , j = 0;
    char [] S = scan.next().toCharArray();
    for(int i=0; i<=N; i++){
      if(S[K]=='('){
        if(S[K+i]=='('){
          j=j+1;
          }else{
          j=j-1;
        }
      }else{
        if(S[K-i]=='('){
          j=j+1;
          }else{
          j=j-1;
        }
      }
      if(j==0){
        ans=i;
        break;
      }
    }
    if(S[K]=='('){
      ans=K+ans+1;
      }else{
      ans=K-ans+1;
    }
    System.out.println(ans);
  }
}
0