結果

問題 No.592 括弧の対応 (2)
ユーザー uafr_csuafr_cs
提出日時 2017-11-10 22:24:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 959 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 3,509 ms
コンパイル使用メモリ 73,624 KB
実行使用メモリ 71,008 KB
最終ジャッジ日時 2023-08-16 02:56:20
合計ジャッジ時間 7,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,720 KB
testcase_01 AC 929 ms
70,772 KB
testcase_02 AC 959 ms
71,008 KB
testcase_03 AC 954 ms
68,912 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