結果

問題 No.592 括弧の対応 (2)
ユーザー uafr_csuafr_cs
提出日時 2017-11-10 22:24:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 979 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 70,204 KB
最終ジャッジ日時 2024-05-03 12:33:54
合計ジャッジ時間 5,526 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
52,832 KB
testcase_01 AC 939 ms
70,204 KB
testcase_02 AC 979 ms
69,848 KB
testcase_03 AC 934 ms
68,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static long MOD = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final char[] chs = sc.next().toCharArray();
		
		LinkedList<Integer> stack = new LinkedList<Integer>();
		int[] pairs = new int[N];
		
		for(int index = 0; index < N; index++){
			if(chs[index] == '('){
				stack.addFirst(index);
			}else{
				final int pair = stack.removeFirst();
				
				pairs[pair] = index;
				pairs[index] = pair;
			}
		}
		
		for(int i = 0; i < N; i++){
			System.out.println(pairs[i] + 1);
		}
	}
}
0