Submission #42927067


Source Code Expand

N = int(input())
v = list(input())


def valid(array):
    j = len(array)

    # print(array[j] == ')', array[j - 1] in ['(', ')'], array[j - 2] == ')')
    for i in range(2, j + 1):
        if array[-i] == ')':
            return -1
        if array[-i] == '(':
            return i
    return -1

answer = v[:1]
left = 0
for i in range(1, N):
    if v[i] == '(':
        left += 1
    answer.append(v[i])
    while left > 0 and answer and answer[-1] == ')':
        back = valid(answer)
        if back > 0:
            # print(answer, back)
            answer = answer[:-back]
            left -= 1
        else:
            break
print(''.join(answer))


# 8
# a((bd))c

Submission Info

Submission Time
Task D - Mismatched Parentheses
User cocodrips
Language PyPy3 (7.3.0)
Score 0
Code Size 706 Byte
Status WA
Exec Time 2213 ms
Memory 185488 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
WA × 1
AC × 38
WA × 8
TLE × 2
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 162 ms 61624 KiB
random_02.txt WA 57 ms 61672 KiB
random_03.txt WA 55 ms 61564 KiB
random_04.txt WA 56 ms 61652 KiB
random_05.txt AC 56 ms 61752 KiB
random_06.txt AC 54 ms 61664 KiB
random_07.txt AC 53 ms 61776 KiB
random_08.txt AC 57 ms 61828 KiB
random_09.txt AC 54 ms 61732 KiB
random_10.txt AC 51 ms 61728 KiB
random_11.txt AC 51 ms 61568 KiB
random_12.txt AC 57 ms 61480 KiB
random_13.txt WA 53 ms 61712 KiB
random_14.txt AC 57 ms 61548 KiB
random_15.txt AC 57 ms 61764 KiB
random_16.txt AC 88 ms 87468 KiB
random_17.txt AC 73 ms 77980 KiB
random_18.txt AC 79 ms 87524 KiB
random_19.txt AC 63 ms 71272 KiB
random_20.txt AC 168 ms 152836 KiB
random_21.txt AC 65 ms 69064 KiB
random_22.txt AC 114 ms 88540 KiB
random_23.txt AC 67 ms 67904 KiB
random_24.txt AC 156 ms 79168 KiB
random_25.txt AC 105 ms 73012 KiB
random_26.txt AC 169 ms 79768 KiB
random_27.txt AC 125 ms 77012 KiB
random_28.txt WA 188 ms 77844 KiB
random_29.txt AC 101 ms 71468 KiB
random_30.txt AC 147 ms 77828 KiB
random_31.txt AC 101 ms 70844 KiB
random_32.txt AC 82 ms 87116 KiB
random_33.txt TLE 2213 ms 185488 KiB
random_34.txt AC 98 ms 87568 KiB
random_35.txt AC 83 ms 87356 KiB
random_36.txt AC 95 ms 103796 KiB
random_37.txt TLE 2212 ms 181820 KiB
random_38.txt AC 113 ms 103764 KiB
random_39.txt AC 94 ms 98840 KiB
random_40.txt WA 80 ms 77788 KiB
random_41.txt WA 82 ms 77676 KiB
random_42.txt AC 51 ms 61888 KiB
random_43.txt AC 59 ms 61668 KiB
random_44.txt AC 55 ms 61816 KiB
sample_01.txt AC 54 ms 61824 KiB
sample_02.txt AC 54 ms 61784 KiB
sample_03.txt WA 56 ms 61784 KiB
sample_04.txt AC 56 ms 61816 KiB