結果

問題 No.22 括弧の対応
ユーザー UEUEUE66UEUEUE66
提出日時 2019-06-15 04:37:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 74,932 KB
実行使用メモリ 58,520 KB
最終ジャッジ日時 2023-08-10 14:59:31
合計ジャッジ時間 6,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,032 KB
testcase_01 AC 113 ms
56,156 KB
testcase_02 AC 112 ms
55,896 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 118 ms
56,016 KB
testcase_18 AC 114 ms
55,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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 count = 0;
        String[] sp = s.split("");
        List<String> kakko = new ArrayList<>();
        List<Integer> num = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            kakko.add(sp[i]);
            if (kakko.get(i).equals("(")) {
                count++;
                num.add(count);
            } else {
                count--;
                num.add(count);
            }
        }


        if (kakko.get(k-1).equals("(")) {
            for (int i = k-1; i < n; i++) {
                if (num.get(i).equals(num.get(k-1)-1) && kakko.get(i).equals(")")) System.out.println(i+1);
            }
        } else {
            for (int i = 0; i < k-1; i++) {
                if (num.get(i).equals(num.get(k-1)+1) && kakko.get(i).equals("(")) System.out.println(i+1);
            }
        }
    }
}
0