It broke through in 25 minutes, but since it is WA1, it is treated as 30 minutes.
The space between > <
is 0, and the space between <>
is the larger one that has been incremented by 1 from 0 on the left and right, so it can be solved with 2 passes as shown below.
S = input()
N = len(S) + 1
t = [0] * N
for i in range(N - 1):
if S[i] == '<':
t[i + 1] = t[i] + 1
for i in range(N - 2, -1, -1):
if S[i] == '>':
t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))
Defeated completely untouched.
Recommended Posts