結果

問題 No.22 括弧の対応
ユーザー aaaaasatori
提出日時 2018-02-14 20:27:09
言語 Java
(openjdk 23)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 500 bytes
コンパイル時間 3,486 ms
コンパイル使用メモリ 74,400 KB
実行使用メモリ 42,424 KB
最終ジャッジ日時 2024-07-20 07:29:39
合計ジャッジ時間 7,256 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No22 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		String str[] = S.split("");
		int count = 0;
		int i = K - 1;
		while(true) {
			if(str[i].equals("(")){
				count++;
			}else {
				count--;
			}
			
			if(count == 0) {
				break;
			}
			
			if(str[K - 1].equals("(")) {
				i++;
			}else {
				i--;
			}
		}
		
		System.out.println(i + 1);
	}
}
0