結果

問題 No.592 括弧の対応 (2)
ユーザー 37zigen37zigen
提出日時 2018-05-27 19:32:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 962 ms / 5,000 ms
コード長 829 bytes
コンパイル時間 3,109 ms
コンパイル使用メモリ 74,272 KB
実行使用メモリ 64,780 KB
最終ジャッジ日時 2023-09-11 04:43:28
合計ジャッジ時間 7,105 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,644 KB
testcase_01 AC 930 ms
64,780 KB
testcase_02 AC 962 ms
64,556 KB
testcase_03 AC 924 ms
63,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String str = sc.next();
		int[] pre = new int[N];
		for (int i = 0; i < N; ++i) {
			pre[i] = i - 1;
		}
		int[] ans = new int[N];
		for (int i = 0; i < N; ++i) {
			if (pre[i] >= 0 && str.charAt(i) == ')' && str.charAt(pre[i]) == '(') {
				ans[pre[i]] = i;
				ans[i] = pre[i];
				if (i + 1 < N && pre[i] >= 0)
					pre[i + 1] = pre[pre[i]];
			}
		}
		for (int i = 0; i < N; ++i) {
			System.out.println(ans[i] + 1);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0