結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-30 16:36:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,071 ms / 5,000 ms |
| コード長 | 623 bytes |
| コンパイル時間 | 2,045 ms |
| コンパイル使用メモリ | 74,352 KB |
| 実行使用メモリ | 58,744 KB |
| 最終ジャッジ日時 | 2024-06-26 23:40:57 |
| 合計ジャッジ時間 | 6,036 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
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]);
}
}