結果

問題 No.457 (^^*)
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-26 15:02:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 8,612 KB
最終ジャッジ日時 2023-09-20 11:01:55
合計ジャッジ時間 1,563 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,980 KB
testcase_01 AC 16 ms
7,972 KB
testcase_02 AC 15 ms
7,844 KB
testcase_03 AC 17 ms
8,112 KB
testcase_04 AC 17 ms
8,048 KB
testcase_05 AC 18 ms
8,104 KB
testcase_06 AC 16 ms
7,896 KB
testcase_07 AC 16 ms
8,048 KB
testcase_08 AC 17 ms
8,072 KB
testcase_09 AC 18 ms
8,128 KB
testcase_10 AC 20 ms
8,384 KB
testcase_11 AC 25 ms
8,372 KB
testcase_12 AC 25 ms
8,328 KB
testcase_13 AC 21 ms
8,516 KB
testcase_14 AC 27 ms
8,612 KB
testcase_15 AC 24 ms
8,364 KB
testcase_16 AC 26 ms
8,520 KB
testcase_17 AC 22 ms
8,476 KB
testcase_18 AC 15 ms
8,100 KB
testcase_19 AC 17 ms
8,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(S):
    L = count_faces(S[::-1], ')(')
    R = count_faces(S)
    return L, R

def count_faces(S, parens = '()'):
    n = len(S)
    open_paren = parens[0]
    close_paren = parens[1]
    next_star_pos = set_next_pos(S, '*')
    cums_hat = set_cum_count(S, '^')
    cums_paren = set_cum_count(S, close_paren)
    counts = 0
    right_idx = 1
    for left_idx, c in enumerate(S):
        if c == open_paren:
            star_pos = next_star_pos[left_idx]
            if star_pos  >= n:
                break
            for right_idx in range(right_idx, n):
                if S[right_idx] == close_paren:
                    if cums_hat[right_idx] - cums_hat[star_pos] >= 2:
                        break
            else:
                break
            counts += cums_paren[-1] - cums_paren[right_idx] + 1
    return counts


def set_next_pos(S, c):
    n = len(S)
    nps = [n] * n
    np = n
    for pos in range(n - 1, -1, -1):
        if S[pos] == c:
            np = pos
        nps[pos] = np
    return nps

def set_cum_count(S, c):
    n = len(S)
    cums = [0] * n
    cum = 0
    for pos, s in enumerate(S):
        if s == c:
            cum += 1
        cums[pos] = cum
    return cums

S = input().rstrip()
print(*solve(S))
0