Submission #3011888


Source Code Expand

S = input()

dp = [[[-1 for k in range(len(S))] for j in range(len(S))] for i in range(len(S))]


def rec(idx, cur, t):
    """

    :param int idx: 現在見ているインデックス
    :param int cur: 最後に文字を変更したインデックス(カーソルの位置)
    :param int t:'('が')'よりどれだけ多いか
    :return int res: (idx, cur, t)における操作回数の最小値
    """
    if idx == len(S) and t == 0:
        return cur
    if t < 0 or idx == len(S) and t != 0:
        return 1000
    if dp[idx][cur][t] != -1:
        return dp[idx][cur][t]

    if S[idx] == "(":
        res1 = rec(idx+1, idx, t-1) + 1
        res2 = rec(idx+1, cur, t+1)
    else:
        res1 = rec(idx+1, idx, t+1) + 1
        res2 = rec(idx+1, cur, t-1)

    res = min(res1, res2)
    dp[idx][cur][t] = res

    return res


ans = rec(0, 0, 0)
print(ans)

Submission Info

Submission Time
Task B - 天下一魔力発電
User cherrypi59
Language Python (3.4.3)
Score 400
Code Size 905 Byte
Status AC
Exec Time 179 ms
Memory 12148 KB

Judge Result

Set Name All
Score / Max Score 400 / 400
Status
AC × 32
Set Name Test Cases
All 01_sample_01, 01_sample_02, 01_sample_03, 02_manual_01, 02_manual_02, 02_manual_03, 10_random_00, 10_random_01, 10_random_02, 10_random_03, 10_random_04, 10_random_05, 10_random_06, 10_random_07, 10_random_08, 10_random_09, 10_random_10, 10_random_11, 10_random_12, 10_random_13, 10_random_14, 10_random_15, 10_random_16, 10_random_17, 10_random_18, 10_random_19, 20_max_00, 20_max_01, 20_max_02, 20_max_03, 20_max_04, 20_max_05
Case Name Status Exec Time Memory
01_sample_01 AC 17 ms 3064 KB
01_sample_02 AC 17 ms 3064 KB
01_sample_03 AC 17 ms 3064 KB
02_manual_01 AC 17 ms 3064 KB
02_manual_02 AC 18 ms 3064 KB
02_manual_03 AC 17 ms 3064 KB
10_random_00 AC 28 ms 3828 KB
10_random_01 AC 18 ms 3064 KB
10_random_02 AC 26 ms 3572 KB
10_random_03 AC 64 ms 6132 KB
10_random_04 AC 18 ms 3064 KB
10_random_05 AC 19 ms 3188 KB
10_random_06 AC 29 ms 3828 KB
10_random_07 AC 142 ms 11124 KB
10_random_08 AC 51 ms 5364 KB
10_random_09 AC 19 ms 3064 KB
10_random_10 AC 19 ms 3064 KB
10_random_11 AC 17 ms 3064 KB
10_random_12 AC 99 ms 8180 KB
10_random_13 AC 111 ms 8436 KB
10_random_14 AC 18 ms 3064 KB
10_random_15 AC 19 ms 3188 KB
10_random_16 AC 129 ms 10740 KB
10_random_17 AC 119 ms 8948 KB
10_random_18 AC 135 ms 10740 KB
10_random_19 AC 122 ms 10484 KB
20_max_00 AC 177 ms 12148 KB
20_max_01 AC 130 ms 12148 KB
20_max_02 AC 154 ms 12148 KB
20_max_03 AC 152 ms 12148 KB
20_max_04 AC 179 ms 12148 KB
20_max_05 AC 173 ms 12148 KB