結果

問題 No.22 括弧の対応
ユーザー jp_stejp_ste
提出日時 2016-02-18 22:06:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 815 bytes
コンパイル時間 3,655 ms
コンパイル使用メモリ 78,036 KB
実行使用メモリ 57,876 KB
最終ジャッジ日時 2023-10-23 18:13:36
合計ジャッジ時間 7,240 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
57,360 KB
testcase_01 AC 137 ms
57,396 KB
testcase_02 AC 141 ms
57,500 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 139 ms
57,376 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		try (Scanner scan = new Scanner(System.in)) {
			int N = scan.nextInt();
			int K = scan.nextInt();
			String S = scan.next();
			
			ArrayList<Node> list = new ArrayList<>();
			int count = 0;
			for(int i=0; i<S.length(); i++) {
				if(S.charAt(i) == '(') {
					list.add(new Node(i+1));
					count++;
				} else if(S.charAt(i) == ')') {
					count--;
					list.get(count).end = i+1;
				}
			}
			
			for(int i=0; i<list.size(); i++) {
				if(list.get(i).first == K) {
					System.out.println(list.get(i).end);
				} else if(list.get(i).end == K) {
					System.out.println(list.get(i).first);
				}
			}
		}
	}
}

class Node {
	int first;
	int end;
	Node(int f) {
		first = f;
		end = -1;
	}
}
0