結果

問題 No.22 括弧の対応
ユーザー fal_rndfal_rnd
提出日時 2017-04-02 20:43:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 698 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 56,372 KB
最終ジャッジ日時 2023-09-27 13:12:49
合計ジャッジ時間 5,078 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,232 KB
testcase_01 AC 114 ms
56,096 KB
testcase_02 AC 115 ms
56,004 KB
testcase_03 AC 134 ms
56,172 KB
testcase_04 AC 132 ms
56,048 KB
testcase_05 AC 127 ms
56,216 KB
testcase_06 AC 127 ms
56,160 KB
testcase_07 AC 129 ms
56,372 KB
testcase_08 AC 128 ms
55,772 KB
testcase_09 AC 127 ms
56,088 KB
testcase_10 AC 127 ms
56,104 KB
testcase_11 AC 127 ms
55,892 KB
testcase_12 AC 129 ms
56,088 KB
testcase_13 AC 129 ms
56,172 KB
testcase_14 AC 116 ms
56,096 KB
testcase_15 AC 129 ms
55,912 KB
testcase_16 AC 124 ms
56,220 KB
testcase_17 AC 113 ms
55,796 KB
testcase_18 AC 115 ms
56,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}


	static int n,k;
	static String in;
	private static void input(){
		n=s.nextInt();
		k=s.nextInt()-1;
		in=s.next();
	}

	private static void solve(){
		int depth=0,i=k;
		switch(in.charAt(k)){
		case '(':
			while(true) {
				i++;
				if(depth==0&&in.charAt(i)==')') {
					System.out.println(i+1);
					return;
				}
				depth+=in.charAt(i)=='('?1:-1;
			}
		case ')':
			while(true) {
				i--;
				if(depth==0&&in.charAt(i)=='(') {
					System.out.println(i+1);
					return;
				}
				depth+=in.charAt(i)==')'?1:-1;
			}
		}
	}
}
0