結果

問題 No.592 括弧の対応 (2)
ユーザー takeya_okinotakeya_okino
提出日時 2017-11-11 20:19:52
言語 Java19
(openjdk 21)
結果
AC  
実行時間 980 ms / 5,000 ms
コード長 554 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 72,420 KB
実行使用メモリ 66,504 KB
最終ジャッジ日時 2023-08-16 07:48:16
合計ジャッジ時間 6,219 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,884 KB
testcase_01 AC 924 ms
66,220 KB
testcase_02 AC 914 ms
66,504 KB
testcase_03 AC 980 ms
66,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    Stack<Integer> stack = new Stack<Integer>();
    int[] cor = new int[n];
    for(int i = 0; i < n; i++) {
      char c = s.charAt(i);
      if(c == '(') {
        stack.push(i + 1);
      } else {
        int pos = stack.pop();
        cor[pos - 1] = i + 1;
        cor[i] = pos; 
      }
    }
    for(int i = 0; i < n; i++) {
      System.out.println(cor[i]);
    }
  }
}
0