結果
| 問題 | No.457 (^^*) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-26 15:02:14 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 2,000 ms |
| コード長 | 1,250 bytes |
| 記録 | |
| コンパイル時間 | 517 ms |
| コンパイル使用メモリ | 20,700 KB |
| 実行使用メモリ | 15,356 KB |
| 最終ジャッジ日時 | 2026-03-27 17:41:59 |
| 合計ジャッジ時間 | 3,269 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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))