結果
問題 | No.457 (^^*) |
ユーザー |
|
提出日時 | 2017-03-26 15:02:14 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,250 bytes |
コンパイル時間 | 85 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-06 06:28:42 |
合計ジャッジ時間 | 1,456 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
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))