結果

問題 No.22 括弧の対応
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-11 22:36:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 686 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 74,380 KB
実行使用メモリ 57,892 KB
最終ジャッジ日時 2023-10-24 21:24:14
合計ジャッジ時間 5,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,488 KB
testcase_01 AC 127 ms
57,552 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 143 ms
57,712 KB
testcase_07 AC 144 ms
57,304 KB
testcase_08 AC 132 ms
56,312 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 139 ms
57,708 KB
testcase_13 AC 140 ms
57,556 KB
testcase_14 WA -
testcase_15 AC 144 ms
57,644 KB
testcase_16 AC 142 ms
57,416 KB
testcase_17 AC 125 ms
57,288 KB
testcase_18 AC 128 ms
57,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String s = sc.next();
    int[] coresspond = new int[N];
    int a = 0;
    int b = N - 1;
    while(a < b) {
      if(s.charAt(a + 1) == ')') {
        coresspond[a] = a + 1;
        coresspond[a + 1] = a;
        a += 2;
      } else if(s.charAt(b - 1) == '(') {
        coresspond[b] = b - 1;
        coresspond[b - 1] = b;
        b -= 2;
      } else {
        coresspond[a] = b;
        coresspond[b] = a;
        a++;
        b--;
      } 
    }
    System.out.println(coresspond[K - 1] + 1);
  }
}
0