結果

問題 No.457 (^^*)
ユーザー htkbhtkb
提出日時 2018-05-25 12:41:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 8,684 KB
最終ジャッジ日時 2023-09-11 03:24:07
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,964 KB
testcase_01 AC 16 ms
8,016 KB
testcase_02 AC 16 ms
8,052 KB
testcase_03 AC 16 ms
7,992 KB
testcase_04 AC 16 ms
7,984 KB
testcase_05 AC 16 ms
8,020 KB
testcase_06 AC 16 ms
7,992 KB
testcase_07 AC 16 ms
8,004 KB
testcase_08 AC 18 ms
7,964 KB
testcase_09 AC 19 ms
7,984 KB
testcase_10 AC 24 ms
8,292 KB
testcase_11 AC 31 ms
8,536 KB
testcase_12 AC 33 ms
8,524 KB
testcase_13 AC 43 ms
8,100 KB
testcase_14 AC 22 ms
8,492 KB
testcase_15 AC 33 ms
8,560 KB
testcase_16 AC 43 ms
8,232 KB
testcase_17 AC 22 ms
8,684 KB
testcase_18 AC 16 ms
7,932 KB
testcase_19 AC 16 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
length = len(S)
p_cumsum = [0]*(length+1)
dp = [[-1]*(length+1) for _ in [0]*2]
for c, i in zip(S[::-1], range(length-1, -1, -1)):
    p_cumsum[i] = p_cumsum[i+1] + (c == ")")

cnt = [0]
def hoge(i, parts, dp):
    cnt[0] += 1
    if dp[i] != -1:
        return dp[i]

    if not parts:
        return p_cumsum[i]
    j = i
    while j < length and S[j] != parts[0]:
        j += 1
    j += 1
    value = hoge(j, parts[1:], dp) if j < length else 0
    if len(parts) == 3:
        for k in range(i, j):
            dp[k] = value
    return value


right, left = "* ^ ^".split(), "^ ^ *".split()
result = [0, 0]
prev = [0, 0]
for i, c in enumerate(S):
    if c != "(":
        continue
    subs = S[i+1:]
    for j, parts in enumerate((left, right)):
        _cnt = cnt[0]
        dp[j][i] = hoge(i+1, parts, dp[j])
        result[j] += dp[j][i]

print(result[0], result[1])
0