結果
| 問題 | No.592 括弧の対応 (2) |
| コンテスト | |
| ユーザー |
37zigen
|
| 提出日時 | 2018-05-27 19:32:49 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 497 ms / 5,000 ms |
| コード長 | 829 bytes |
| 記録 | |
| コンパイル時間 | 1,572 ms |
| コンパイル使用メモリ | 83,464 KB |
| 実行使用メモリ | 56,628 KB |
| 最終ジャッジ日時 | 2026-03-17 20:57:24 |
| 合計ジャッジ時間 | 4,319 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
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));
}
}
37zigen