結果
問題 | No.592 括弧の対応 (2) |
ユーザー | htensai |
提出日時 | 2019-11-14 18:22:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 363 ms / 5,000 ms |
コード長 | 671 bytes |
コンパイル時間 | 2,136 ms |
コンパイル使用メモリ | 75,776 KB |
実行使用メモリ | 68,252 KB |
最終ジャッジ日時 | 2023-10-21 20:01:30 |
合計ジャッジ時間 | 4,495 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
57,044 KB |
testcase_01 | AC | 352 ms
67,252 KB |
testcase_02 | AC | 363 ms
68,252 KB |
testcase_03 | AC | 319 ms
62,256 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] arr = sc.next().toCharArray(); HashMap<Integer, Integer> map = new HashMap<>(); int level = 0; int[] ans = new int[n]; for (int i = 0; i < n; i++) { if (arr[i] == '(') { level++; map.put(level, i); } else { int idx = map.get(level); ans[idx] = i + 1; ans[i] = idx + 1; level--; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } }