Submission #42909300


Source Code Expand

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

public class Main{
    static Scanner sc = new Scanner(System.in);

    public static void solve() {
        int n = sc.nextInt();
        char[]chars = sc.next().toCharArray();
        LinkedList<Character>list = new LinkedList<>();
        int cnt = 0;
        for(char c : chars){
            if(c != '(' && c != ')'){
                list.add(c);
                continue;
            }
            if(c =='('){
                cnt++;
                list.add(c);
                continue;
            }else{
                if(cnt != 0){
                    cnt--;
                    while (list.getLast() != '('){
                        list.pollLast();
                    }
                    list.pollLast();
                }else{
                    list.add(c);
                }
            }
        }
        StringBuilder bd = new StringBuilder();
        for(char c : list){
            bd.append(c);
        }
        System.out.println(bd.toString());
    }

    public static char[][] getG(int n,int m){
       char[][]chars = new char[n][m];
        for (int i = 0; i < n; i++) {
            chars[i] = sc.next().toCharArray();
        }
        return chars;
    }

    public static void main(String[] args) {
        int n = 1;
        for (int i = 0; i < n; i++) {
            solve();
        }
    }
}

Submission Info

Submission Time
Task D - Mismatched Parentheses
User liuji
Language Java (OpenJDK 1.8.0)
Score 400
Code Size 1442 Byte
Status AC
Exec Time 205 ms
Memory 38268 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 48
Set Name Test Cases
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
Case Name Status Exec Time Memory
random_01.txt AC 92 ms 26712 KiB
random_02.txt AC 97 ms 26888 KiB
random_03.txt AC 84 ms 26868 KiB
random_04.txt AC 90 ms 27020 KiB
random_05.txt AC 87 ms 26748 KiB
random_06.txt AC 89 ms 26776 KiB
random_07.txt AC 85 ms 26820 KiB
random_08.txt AC 85 ms 27028 KiB
random_09.txt AC 93 ms 26832 KiB
random_10.txt AC 90 ms 26768 KiB
random_11.txt AC 88 ms 26832 KiB
random_12.txt AC 83 ms 26888 KiB
random_13.txt AC 85 ms 27028 KiB
random_14.txt AC 84 ms 26732 KiB
random_15.txt AC 85 ms 27000 KiB
random_16.txt AC 196 ms 37840 KiB
random_17.txt AC 158 ms 33240 KiB
random_18.txt AC 187 ms 37852 KiB
random_19.txt AC 137 ms 29944 KiB
random_20.txt AC 182 ms 36400 KiB
random_21.txt AC 112 ms 28324 KiB
random_22.txt AC 178 ms 36460 KiB
random_23.txt AC 101 ms 27408 KiB
random_24.txt AC 180 ms 36168 KiB
random_25.txt AC 163 ms 32456 KiB
random_26.txt AC 175 ms 36148 KiB
random_27.txt AC 168 ms 35244 KiB
random_28.txt AC 179 ms 34044 KiB
random_29.txt AC 141 ms 31160 KiB
random_30.txt AC 180 ms 34076 KiB
random_31.txt AC 144 ms 31096 KiB
random_32.txt AC 198 ms 38120 KiB
random_33.txt AC 174 ms 33904 KiB
random_34.txt AC 195 ms 38172 KiB
random_35.txt AC 203 ms 37980 KiB
random_36.txt AC 194 ms 37808 KiB
random_37.txt AC 169 ms 34052 KiB
random_38.txt AC 204 ms 38268 KiB
random_39.txt AC 205 ms 38220 KiB
random_40.txt AC 183 ms 33968 KiB
random_41.txt AC 173 ms 34108 KiB
random_42.txt AC 87 ms 26868 KiB
random_43.txt AC 94 ms 26852 KiB
random_44.txt AC 89 ms 26868 KiB
sample_01.txt AC 86 ms 26856 KiB
sample_02.txt AC 88 ms 26856 KiB
sample_03.txt AC 89 ms 26860 KiB
sample_04.txt AC 90 ms 26780 KiB