提出 #42913010


ソースコード 拡げる

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			String s = scanner.next();
			LinkedList<List<Character>> list = new LinkedList<>();
			List<Character> temp = new ArrayList<>();
			for (int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				if (c == '(') {
					if (temp.size() > 0) {
						list.add(temp);
						temp = new ArrayList<>();
					}
					temp.add(c);
				} else if (c == ')') {
					if (temp.size() > 0 && temp.get(0) == '(') {
						if (list.size() > 0) {
							temp = list.removeLast();
						} else {
							temp = new ArrayList<>();
						}
					} else {
						temp.add(c);
					}
				} else {
					temp.add(c);
				}
			}
			list.add(temp);

			StringBuilder builder = new StringBuilder();
			for (List<Character> characters : list) {
				characters.forEach(builder::append);
			}

			System.out.println(builder);
		}
	}
}

提出情報

提出日時
問題 D - Mismatched Parentheses
ユーザ kmatsu
言語 Java (OpenJDK 11.0.6)
得点 400
コード長 1116 Byte
結果 AC
実行時間 361 ms
メモリ 79960 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 48
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 158 ms 35888 KiB
random_02.txt AC 109 ms 35868 KiB
random_03.txt AC 113 ms 35612 KiB
random_04.txt AC 114 ms 35952 KiB
random_05.txt AC 106 ms 35856 KiB
random_06.txt AC 115 ms 35960 KiB
random_07.txt AC 112 ms 35860 KiB
random_08.txt AC 109 ms 35832 KiB
random_09.txt AC 113 ms 35776 KiB
random_10.txt AC 107 ms 35708 KiB
random_11.txt AC 115 ms 35928 KiB
random_12.txt AC 111 ms 35864 KiB
random_13.txt AC 118 ms 35820 KiB
random_14.txt AC 115 ms 35740 KiB
random_15.txt AC 104 ms 35820 KiB
random_16.txt AC 262 ms 57072 KiB
random_17.txt AC 222 ms 48152 KiB
random_18.txt AC 260 ms 56588 KiB
random_19.txt AC 165 ms 41064 KiB
random_20.txt AC 213 ms 45380 KiB
random_21.txt AC 133 ms 36944 KiB
random_22.txt AC 211 ms 44844 KiB
random_23.txt AC 131 ms 36272 KiB
random_24.txt AC 207 ms 43996 KiB
random_25.txt AC 190 ms 41268 KiB
random_26.txt AC 213 ms 44104 KiB
random_27.txt AC 212 ms 43404 KiB
random_28.txt AC 231 ms 51280 KiB
random_29.txt AC 202 ms 44140 KiB
random_30.txt AC 238 ms 50884 KiB
random_31.txt AC 197 ms 43428 KiB
random_32.txt AC 286 ms 56696 KiB
random_33.txt AC 238 ms 50904 KiB
random_34.txt AC 336 ms 66280 KiB
random_35.txt AC 337 ms 78232 KiB
random_36.txt AC 286 ms 57000 KiB
random_37.txt AC 226 ms 50864 KiB
random_38.txt AC 330 ms 66516 KiB
random_39.txt AC 361 ms 79960 KiB
random_40.txt AC 216 ms 48780 KiB
random_41.txt AC 229 ms 50348 KiB
random_42.txt AC 107 ms 35776 KiB
random_43.txt AC 101 ms 35620 KiB
random_44.txt AC 113 ms 35796 KiB
sample_01.txt AC 111 ms 35908 KiB
sample_02.txt AC 110 ms 35744 KiB
sample_03.txt AC 115 ms 35844 KiB
sample_04.txt AC 107 ms 35820 KiB