結果

問題 No.457 (^^*)
ユーザー compass19
提出日時 2016-12-10 22:17:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,238 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,632 KB
最終ジャッジ日時 2024-11-29 02:14:11
合計ジャッジ時間 13,128 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

# -----------
# yukicoder
# No.457 (^^*)
# http://yukicoder.me/problems/no/457
# -------


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())
0