Created
December 10, 2016 13:20
-
-
Save nariaki3551/5a48a9cde58cdcca1cbe4fa2a3f55243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------- | |
# yukicoder | |
# No.457 (^^*) | |
# http://yukicoder.me/problems/no/457 | |
# ------- | |
# TLE もっと早い実装はできないのか........ | |
s = input() | |
left_pos = [i for i, k in enumerate(s) if k == '('] | |
def left_solve(): | |
res = 0 | |
tmp_stock = None | |
first_index = None | |
for i in left_pos: | |
if tmp_stock is not None: | |
if i < first_index: | |
res += tmp_stock | |
continue | |
else: | |
tmp_stock = None | |
first_index = None | |
tmp = s[i+1:] | |
count = 0 | |
for j, elm in enumerate(tmp): | |
if count < 2: | |
if elm == '^': | |
if first_index is None: first_index = i + j | |
count += 1 | |
else: | |
if elm == '*': | |
tmp_stock = tmp[j+1:].count(')') | |
res += tmp_stock | |
break | |
return res | |
def right_solve(): | |
res = 0 | |
tmp_stock = None | |
first_index = None | |
for i in left_pos: | |
if tmp_stock is not None: | |
if i < first_index: | |
res += tmp_stock | |
continue | |
else: | |
tmp_stock = None | |
first_index = None | |
tmp = s[i+1:] | |
count = 0 | |
for j, elm in enumerate(tmp): | |
if count < 1: | |
if elm == '*': | |
if first_index is None: first_index = i + j | |
count += 1 | |
elif count < 2: | |
if elm == '^': | |
count += 1 | |
else: | |
if elm == '^': | |
tmp_stock = tmp[j+1:].count(')') | |
res += tmp_stock | |
break | |
return res | |
print(left_solve(), right_solve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment