結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-27 19:32:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 985 ms / 5,000 ms |
| コード長 | 829 bytes |
| コンパイル時間 | 2,243 ms |
| コンパイル使用メモリ | 77,788 KB |
| 実行使用メモリ | 56,056 KB |
| 最終ジャッジ日時 | 2024-06-28 19:09:26 |
| 合計ジャッジ時間 | 6,265 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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));
}
}