結果

問題 No.22 括弧の対応
ユーザー lrf141lrf141
提出日時 2016-11-27 09:54:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 3,934 ms
コンパイル使用メモリ 71,968 KB
実行使用メモリ 58,248 KB
最終ジャッジ日時 2023-08-18 08:20:52
合計ジャッジ時間 7,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,672 KB
testcase_01 AC 124 ms
55,992 KB
testcase_02 AC 124 ms
55,684 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 123 ms
55,636 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class no22{
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        String s = scan.next();

        int a[] = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = 0;

        int deep = 0,check=0,check_i=0,check_c;
        a[0] = deep;
        for(int i = 1; i < n; i++){
            
            if(s.charAt(i) != s.charAt(i-1)){
                a[i] = deep;
            }else{
                if(s.charAt(i) == '(')
                    deep++;
                else
                    deep--;

                a[i] = deep;
                if(i == k-1){
                    check = deep;
                    check_i = i;
                }
            }
        }

        int ans;
        for(ans = 0; ans < n; ans++){
            if(a[ans] == check && check_i != ans){
                System.out.println(ans+1);
            }
        }

    }
}
0