結果

問題 No.22 括弧の対応
ユーザー k_kadorak_kadora
提出日時 2015-06-10 23:23:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 759 bytes
コンパイル時間 5,916 ms
コンパイル使用メモリ 79,512 KB
実行使用メモリ 56,072 KB
最終ジャッジ日時 2023-09-27 12:55:03
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,688 KB
testcase_01 AC 113 ms
56,056 KB
testcase_02 AC 114 ms
55,460 KB
testcase_03 AC 127 ms
54,056 KB
testcase_04 AC 125 ms
56,044 KB
testcase_05 AC 122 ms
55,712 KB
testcase_06 AC 120 ms
55,948 KB
testcase_07 AC 128 ms
55,932 KB
testcase_08 AC 126 ms
55,932 KB
testcase_09 AC 127 ms
55,760 KB
testcase_10 AC 124 ms
56,072 KB
testcase_11 AC 122 ms
55,732 KB
testcase_12 AC 123 ms
55,848 KB
testcase_13 AC 122 ms
55,784 KB
testcase_14 AC 116 ms
55,800 KB
testcase_15 AC 128 ms
55,684 KB
testcase_16 AC 130 ms
55,896 KB
testcase_17 AC 114 ms
55,776 KB
testcase_18 AC 115 ms
55,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Kakko{
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		int n,k,res=0,count=0,kc,c,temp=0;
		String s;
		n = sc.nextInt();
		k = sc.nextInt();
		s = sc.next();
		int[] m = new int[n];
		for(int i = 0;i<n;i++){
			if(s.charAt(i) == '('){
				count++;
				m[i] = count;
			}else{
				m[i] = count;
				count--;
			}
		}
		count = 0;
		kc = m[k-1];
		for(int i = 0;i<n;i++){
			if(m[i] == kc){
				count++;
				if(i == k - 1){
					c=count;
					if(c%2 == 0){
						res = temp+1;
						break;
					}else{
						i++;
						for(;i<n;i++){
							if(m[i] == kc){
								res = i+1;
								break;
							}
						}
						break;
					}
				}
				temp = i;
			}
		}
		System.out.println(res);
	}
}
0