結果
問題 | No.592 括弧の対応 (2) |
ユーザー | Mcpu3 |
提出日時 | 2018-11-30 16:36:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,072 ms / 5,000 ms |
コード長 | 623 bytes |
コンパイル時間 | 2,283 ms |
コンパイル使用メモリ | 72,304 KB |
実行使用メモリ | 70,152 KB |
最終ジャッジ日時 | 2023-09-09 06:30:26 |
合計ジャッジ時間 | 6,310 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
55,812 KB |
testcase_01 | AC | 893 ms
64,904 KB |
testcase_02 | AC | 1,072 ms
70,152 KB |
testcase_03 | AC | 1,059 ms
69,556 KB |
ソースコード
import java.util.Scanner; class Main { static int top = 0, stack[] = new int[100000]; public static void push(int i) { stack[top] = i; ++top; } public static int pop() { --top; return stack[top]; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(), ans[] = new int[N], tmp; String S = sc.next(); sc.close(); for (int i = 0; i < N; ++i) { if (S.charAt(i) == '(') push(i); else { tmp = pop(); ans[i] = tmp + 1; ans[tmp] = i + 1; } } for (int i = 0; i < N; ++i) System.out.println(ans[i]); } }