結果

問題 No.592 括弧の対応 (2)
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-17 20:49:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 592 bytes
コンパイル時間 3,268 ms
コンパイル使用メモリ 71,788 KB
実行使用メモリ 125,212 KB
最終ジャッジ日時 2023-09-06 17:53:58
合計ジャッジ時間 9,975 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
125,212 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No592 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String str[] = S.split("");
		int taiou[] = new int[N];
		
		for(int i = 0;i < N;i++) {
			if(str[i].equals("(")){
				int cnt = 1;
				for(int j = i+1;j < N;j++) {
					if(str[j].equals("(")) {
						cnt++;
					}else {
						cnt--;
					}
					if(cnt == 0) {
						taiou[i] = j+1;
						taiou[j] = i+1;
						break;
					}
				}
			}
		}
		
		for(int i = 0;i < N;i++) {
			System.out.println(taiou[i]);
		}
	}
}
0