Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Areas on the Cross-Section Diagram

  Your task is to simulate a flood damage.

  For a given cross-section diagram, reports areas of flooded sections.

  Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides.
For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.

Input

  A string, which represents slopes and flatlands by '/', '\' and '_' respectively, is given in a line. For example, the region of the above example is given by a string "\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\".

output

  Report the areas of floods in the following format:

$A$

$k$ $L_1$ $L_2$ ... $L_k$

  In the first line, print the total area $A$ of created floods.

  In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$.

Constraints

$1 \leq$ length of the string $\leq 20,000$

Sample Input 1

\\//

Sample Output 1

4
1 4

Sample Input 2

\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\

Sample Output 2

35
5 4 2 1 19 9



Sample input:
\\//


Sample output:
4
1 4

Submission status: Wrong Answer

Solution code:
class Cell(object):
    def __init__(self, direction, x, y):
        self.direction = direction
        self.x = x
        self.y = y
        self.is_pond = False
        self.never_pond = False
        self.start_of_pond = False
        self.end_of_pond = False

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h - 1
        else:
            return h - 0.5

    @property
    def char(self):
        if self.direction == 'd':
            return '/'
        elif self.direction == 'u':
            return '\\'
        elif self.direction == 'f':
            return '|'

class Area(object):
    def __init__(self):
        self.cells = {}
        self.before_c = ''
        self.x = -1
        self.height = 0
        self.lowest = 0
        self.highest = 0
        self.higher = 0
        self.pond_area = []
        self.reverse = False

    def put(self, c):
        self.x += 1
        if c == '\\':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('d', self.x, self.height)
        elif c == '/':
            if self.before_c == '/' or self.before_c == '_':
                self.height += 1
            self.cells[self.x] = Cell('u', self.x, self.height)
        elif c == '_':
            if self.before_c == '\\':
                self.height -= 1
            self.cells[self.x] = Cell('f', self.x, self.height)
        
        if self.cells[self.x].y < self.lowest:
            self.lowest = self.cells[self.x].y
        if self.highest < self.cells[self.x].y:
            self.highest = self.cells[self.x].y
        self.before_c = c

    def adjust_height(self):
        self.highest -= self.lowest
        for i, c in self.cells.items():
            c.y -= self.lowest
            if self.higher < c.y and c.y < self.highest:
                if c.direction != 'd':
                    self.higher = c.y
    
    def is_pond(self):
        start_of_pond = None
        ponds = []
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            if c_start.is_pond:
                ponds.append(c_start)
            if c_start.direction == 'u':
                if start_of_pond:
                    if start_of_pond.y == c_start.y:
                        start_of_pond = None
                        c_start.end_of_pond = True
                        self.pond_area.append(self.calc_area(ponds))
                        ponds = []
                continue
            if c_start.direction == 'f' and 0 == i_start:
                continue
            if c_start.direction == 'f' and not self.cells[i_start - 1].is_pond:
                continue
            if c_start.direction == 'f' and self.cells[i_start - 1].end_of_pond:
                continue
            if c_start.direction == 'd' or c_start.direction == 'f':
                if c_start.is_pond:
                    continue
            if self.higher > 0 and self.higher < c_start.y:
                continue
            
            for i_end in range(i_start+1, len(self.cells)):
                c_end = self.cells[i_end]
                if c_start.y <= c_end.y:
                    if c_end.direction == 'u':
                        for i in range(c_start.x, c_end.x+1):
                            self.cells[i].is_pond = True
                    elif c_end.direction == 'd':
                        continue
                    elif c_end.direction == 'f':
                        continue
                    break

            if not start_of_pond and c_start.is_pond:
                c_start.start_of_pond = True
                start_of_pond = c_start
            if c_start.is_pond and not c_start in ponds:
                ponds.append(c_start)

    def calc_area(self, ponds):
        area = 0
        height = ponds[0].y
        for c in ponds:
            area += c.get_area(height)
        return int(area)

    def show(self):
        for i, c in self.cells.items():
            p = 'p' if c.is_pond else ' '
            e = 'E' if c.end_of_pond else ''
            s = 'S' if c.start_of_pond else ''
            print('{0:02d}'.format(i) + p + c.char * (c.y+1) + e + s)

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    # area.show()
    print(sum(area.pond_area))
    if area.pond_area:
        print(len(area.pond_area), ' '.join([str(a) for a in area.pond_area]))
    else:
        print(0)

if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
def calcAreas(sections):
    areas = []

    for s in sections:
        if len(s) <= 1:
            continue;

        areas.append(toArea(s))

    return areas

def toArea(section):
    a = 0
    b, _ = section[0]

    for s, e in section:
        a += (max(s, e) - b) - (0.5 if s != e else 0)

    return int(a)

def toDelta(p):
    if '/' == p:
        return -1
    if '\\' == p:
        return 1
    return 0

def toPaths(path):
    h = 0
    ph = 0
    paths = []

    for p in path:
        h += toDelta(p)
        paths.append((ph,h))
        ph = h

    return paths

def update(sections):
    [(lf, ll)] = sections.pop()

    n = None

    for i in range(len(sections)-1, -1, -1):
        if sections[i][0][0] == ll:
            n = i
            break

    if n == None:
        sections.append([(lf, ll)])
        return

    lst = [(lf, ll)]
    for i in range(len(sections)-1, n-1, -1):
        s = sections.pop()
        lst = s + lst

    sections.append(lst)

def main():
    paths = toPaths(input())

    prev = -1
    sections = []

    for f, l in paths:
        sections.append([(f, l)])
        if l < prev:
            update(sections)
        prev = l

    areas = calcAreas(sections)
    l = len(areas)

    print(sum(areas))
    print(l, end='')
    if l > 0:
        print(' {}'.format(' '.join([str(x) for x in areas])), end='')
    print()

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
land = input()
h = 0
H = [0]
for s in land:
    if s == '\\':
        h -= 1
    if s == '/':
        h += 1
    H.append(h)
    
d=0
L = [0]
i = 0
j = 0

for s in land:
#    print(j, H[j])
    if s == "\\" and (H[j] in H[j+1:]):
        if d == 0:
            i += 1
            L.append(0)
        L[i] += 0.5 + d
        d += 1
    elif s == "_":
        L[i] += d
    elif s == "/":
        if d != 0:
            L[i] += d - 0.5
            d = max(0, d-1)
    j += 1
#    print(d, L)
print(int(sum(L)))
print(len(L)-1, *(map(int, L[1:])))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
D = input()
que = deque()
p = 0
for c in D:
    que.append(p)
    if   c == "\\" : p += -1
    elif c == "/"  : p +=  1
que.append(p)

cnt = 0
A = 0
L = []
Li = 0
ps = que.popleft()
pp = ps
while len(que) > 0:
    p = que.popleft()
    if Li == 0 and (p > ps or pp not in que):
            ps = p
    elif p == ps and p > pp:
        Li += 0.5
        cnt += 1
        A += int(Li)
        L.append(int(Li))
        Li = 0
    elif p < ps:
        if   p == pp: Li += ps - p
        elif p <  pp: Li += ps - p - 0.5
        else        : Li += ps - p + 0.5
    pp = p
        
print(A)
print(cnt, *L)

Submission status: Time Limit Exceeded

Solution code:
import sys

class Ground(object):
    def __init__(self, height,types):
        self.height=height
        self.types=types

def calc_areas(grounds,i,j):
    if i >=j:
        return 0
    top_height=grounds[i].height
    k =i
    area=0
    while k<=j:
        diff_height=top_height-grounds[k].height
        if grounds[k].types in (types['down'] ,types['up']):
            area+=diff_height+1.0/2.0
        else:
            area+=diff_height
        k+=1

    return area
        


def find_first_index_by_height(grounds,start_index,height):
    for i in xrange(start_index+1,len(grounds)):
        if grounds[i].height==height:
            return i

    return None

types={}
types['down']='\\'
types['up']='/'
types['flat']='_'


grounds=[]
height=0
for line in sys.stdin:
    for i in xrange(0,len(line)):
        elem=line[i]
        if elem not in types.values():
            break
        if elem == types['down']:
            height-=1
            grounds.append(Ground(height+1,elem))
        elif elem==types['up']:
            height+=1
            grounds.append(Ground(height,elem))
        else:
            grounds.append(Ground(height,elem))



areas=[]
i=0
while i<len(grounds):
    elem=grounds[i]
    j=find_first_index_by_height(grounds,i,elem.height)
    if j is None:
        continue
    area=calc_areas(grounds,i,j)
    if area>0:
        areas.append(area)
        i=j+1
    else:   
        i+=1

print int(sum(areas))
print len(areas),
for i in areas:
    print int(i),

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

class Ground(object):
    def __init__(self, height,types):
        self.height=height
        self.types=types

def calc_areas(grounds,i,j):
    if i >=j:
        return 0
    top_height=grounds[i].height
    k =i
    area=0.0
    while k<=j:
        diff_height=top_height-grounds[k].height
        if grounds[k].types in (types['down'] ,types['up']):
            area+=diff_height+1.0/2.0
        else:
            area+=diff_height
        k+=1

    return area
        


def find_first_index_by_height(grounds,start_index,height):
    for i in xrange(start_index+1,len(grounds)):
        if grounds[i].height==height and grounds[i].types in (types['up'],types['flat']):
            return i

    return None

types={}
types['down']='\\'
types['up']='/'
types['flat']='_'


grounds=[]
height=0
for line in sys.stdin:
    for i in xrange(0,len(line)):
        elem=line[i]
        if elem not in types.values():
            break
        if elem == types['down']:
            height-=1
            grounds.append(Ground(height+1,elem))
        elif elem==types['up']:
            height+=1
            grounds.append(Ground(height,elem))
        else:
            grounds.append(Ground(height,elem))



areas=[]
i=0
while i<len(grounds):
    elem=grounds[i]
    if elem.types != types['down']:
        i+=1
        continue
    j=find_first_index_by_height(grounds,i,elem.height)
    if j is None:
        i+=1
        continue
    area=calc_areas(grounds,i,j)
    if area>0.0:
        areas.append(area)
        i=j+1
    else:   
        i+=1

print int(sum(areas))
print len(areas),
for i in areas:
    print int(i),

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8
def checkDepth(A):
    depth=0
    for i in range(len(A)):
        if A[i]=="\\":
            depth+=1
        elif A[i]=="/":
            depth-=1
        else:
            continue
        if depth==0:
            return True
    return False

def SD(a):
    A=list(a)
    areaList=[]
    areaAll=0
    start=0
    for i in range(len(A)):
        area=0
        if A[i]=="\\":
            Flag=checkDepth(A[i:])
            if Flag==True:
                count=0
                for j in range(i,len(A)):
                    if A[j]=="\\":
                        area+=(count)+0.5
                        count+=1
                    elif A[j]=="/":
                        count-=1
                        area+=(count)+0.5
                    else:
                        area+=count
                    if count==0:
                        for k in range(i,j):
                            A[k]="_"
                        break
                areaList.append(int(area))
                areaAll+=int(area)
                continue
            else:
                continue
        else:
            continue
    print(areaAll)
    for i in range(len(areaList)):
        areaList[i]=str(areaList[i])
    if len(areaList)==0:
        print(str(len(areaList)))
    else:
        print(str(len(areaList))+" "+" ".join(areaList))
        
                    
  
if __name__=="__main__":
    a=input()
    SD(a)

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8
def checkDepth(A):
    depth=0
    for i in range(len(A)):
        if A[i]=="\\":
            depth+=1
        elif A[i]=="/":
            depth-=1
        else:
            continue
        if depth==0:
            return True
    return False

def SD(a):
    A=list(a)
    areaList=[]
    areaAll=0
    start=0
    skip=-1
    for i in range(len(A)):
        if i<skip:
            continue
        area=0
        if A[i]=="\\":
            Flag=checkDepth(A[i:])
            if Flag==True:
                count=0
                for j in range(i,len(A)):
                    if A[j]=="\\":
                        area+=(count)+0.5
                        count+=1
                    elif A[j]=="/":
                        count-=1
                        area+=(count)+0.5
                    else:
                        area+=count
                    if count==0:
                        for k in range(i,j):
                            skip=j
                        break
                areaList.append(int(area))
                areaAll+=int(area)
                continue
            else:
                continue
        else:
            continue
    print(areaAll)
    for i in range(len(areaList)):
        areaList[i]=str(areaList[i])
    if len(areaList)==0:
        print(str(len(areaList)))
    else:
        print(str(len(areaList))+" "+" ".join(areaList))
        
                    
  
if __name__=="__main__":
    a=input()
    SD(a)

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
#?°´??????????????¢????¨????
import re

def cal_puddle(puddle_list):
    depth = 0
    score = 0
    for symbol in puddle_list:
        if symbol == "\\":
            score += depth + 0.5
            depth += 1
        if symbol == "/":
            depth -= 1
            score += depth + 0.5
        if symbol == "_":
            score += depth
            
    return int(score)

def get_puddle_index(diagram_list):

    depth = 0
    for i, symbol in enumerate(diagram_list):
        if symbol == "\\":
            depth += 1
        elif symbol == "/":
            depth = depth - 1

        if depth == 0:
            return i

    return False

def cal(diagram):
    puddle_areas = []
    diagram_list = []

    puddle_list = []
    i = 0
    while i < len(diagram):
        if diagram[i] == "\\":
            puddle_end = get_puddle_index(diagram[i:])
            if puddle_end:
                puddle_list.append(diagram[i: i + puddle_end + 1])
                i = i + puddle_end
        i += 1

    for puddle in puddle_list:
        puddle_areas.append(cal_puddle(puddle))
        
    return puddle_areas

        
if __name__ == "__main__":
    a = input()
    result = cal(a)
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(a) for a in result]))

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
#?°´??????????????¢????¨????
import re

def cal_puddle(puddle_list):
    depth = 0
    score = 0
    for symbol in puddle_list:
        if symbol == "\\":
            score += depth + 0.5
            depth += 1
        if symbol == "/":
            depth -= 1
            score += depth + 0.5
        if symbol == "_":
            score += depth
            
    return int(score)

def get_puddle_index(diagram_list):

    depth = 0
    for i, symbol in enumerate(diagram_list):
        if symbol == "\\":
            depth += 1
        elif symbol == "/":
            depth = depth - 1

        if depth == 0:
            return i

    return False

def cal(diagram):
    puddle_areas = []
    diagram_list = []

    puddle_list = []
    i = 0
    while i < len(diagram):
        if diagram[i] == "\\":
            puddle_end = get_puddle_index(diagram[i:])
            if puddle_end:
                puddle_areas.append(cal_puddle(diagram[i: i + puddle_end + 1]))
                i = i + puddle_end
        i += 1

    for puddle in puddle_list:
        puddle_areas.append(cal_puddle(puddle))
        
    return puddle_areas

        
if __name__ == "__main__":
    a = input()
    result = cal(a)
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(a) for a in result]))

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
#?°´??????????????¢????¨????
import re

def cal_puddle(puddle_list):
    depth = 0
    score = 0
    for symbol in puddle_list:
        if symbol == "\\":
            score += depth + 0.5
            depth += 1
        if symbol == "/":
            depth -= 1
            score += depth + 0.5
        if symbol == "_":
            score += depth
            
    return int(score)

def get_puddle_index(diagram_list):

    depth = 0
    for i, symbol in enumerate(diagram_list):
        if symbol == "\\":
            depth += 1
        elif symbol == "/":
            depth = depth - 1

        if depth == 0:
            return i

    return False

def cal(diagram):
    puddle_areas = []
    diagram_list = []

    puddle_list = []
    i = 0
    while i < len(diagram):
        if diagram[i] == "\\":
            puddle_end = get_puddle_index(diagram[i:])
            if puddle_end:
                puddle_areas.append(cal_puddle(diagram[i: i + puddle_end + 1]))
                i = i + puddle_end
        i += 1

    return puddle_areas

if __name__ == "__main__":
    a = input()
    result = cal(a)
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(a) for a in result]))

Submission status: Time Limit Exceeded

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
#?°´??????????????¢????¨????
import re

def cal_puddle(diagram_list):
    score = 0
    depth = 0
    for i, symbol in enumerate(diagram_list):
        if symbol == "\\":
            score += depth + 0.5
            depth += 1
        elif symbol == "/":
            depth = depth - 1
            score += depth + 0.5
        elif symbol == "_":
            score += depth
            
        if depth == 0:
            return (int(score),i)

    return (False, False)

def cal(diagram):
    
    puddle_areas = []
    diagram_list = []

    puddle_list = []
    i = 0
    score = []
    while i < len(diagram):
        if diagram[i] == "\\":
            res = cal_puddle(diagram[i:])
            if res[1]:
                i = i + res[1]
                score.append(res[0])
        i += 1

    return score

if __name__ == "__main__":
    a = input()
    result = cal(a)
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(a) for a in result]))

Submission status: Time Limit Exceeded

Solution code:
def cal_puddle(puddle):
    depth = 0
    score = 0
    for s in puddle:
        if s == "\\":
            score += depth + 0.5
            depth += 1
        elif s == "/":
            depth -= 1
            score += depth + 0.5
        elif s == "_":
            score += depth

        if depth == 0:
            return int(score)
    return int(score)

def get_puddles(diagram):
    hight = 0
    top_list = []
    in_puddle = True
    for index, s in enumerate(diagram + "\\"):
        if s == "/":
            in_puddle = True
            hight += 1
        if s == "\\":
            if in_puddle:
                in_puddle = False
                top_list.append([hight, index])
            hight -= 1

    puddles = []
    prev_hight = 0
    hight_list = [h for h, i in top_list]
    i = 0
    while i < len(top_list) - 1:
        cur_top = top_list[i]
        next_top = top_list[i + 1]
        if cur_top[0] <= next_top[0]:
            puddles.append((cur_top[1], next_top[1]))
            i = i + 1
        elif cur_top[0] == max(hight_list[i + 1:]):
            
            max_top_index = i + hight_list[i+1:].index(max(hight_list[i + 1:])) + 1
            puddles.append((cur_top[1], top_list[max_top_index][1]))
            i = max_top_index
        elif cur_top[0] > max(hight_list[i + 1:]):
            cur_top[0] -= 1
            cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1
            
    return puddles

def main():
    diagram = input()
    result = []
    for s,e in get_puddles(diagram):
        result.append(cal_puddle(diagram[s:e]))
    print(sum(result))
    print(str(len(result)) + "".join([" " + str(i) for i in result]))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
danmen = input()
depth = []
tmp_dpt = 0

for line in danmen:
    depth.append(tmp_dpt)

    if line == "\\":
        tmp_dpt -= 1
    elif line == "/":
        tmp_dpt += 1

depth.append(tmp_dpt)

# print(depth)

i = 0
L = []

while i < len(danmen):
    if danmen[i] == "\\":
        if depth[i] in depth[i + 1:]:
            stack = 0
            area = 0

            for line in danmen[i:]:
                if line == "\\":
                    area += 1 + 2 * stack
                    stack += 1
                elif line == "/":
                    stack -= 1
                    area += 1 + 2 * stack
                else:
                    area += 2 * stack

                if stack == 0:
                    break

            if area != 0:
                L.append(area // 2)
                i += depth[i + 1:].index(depth[i])
        
    i += 1

print(sum(L))
print(len(L), *L)

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
h = [0]
for i in range(len(l)):
    if l[i] == "\\":
        h.append(h[i]-1)
    elif l[i] == "/":
        h.append(h[i]+1)
    else:
        h.append(h[i])
A = 0
k = 0
L = []      
i = 0  
while i in range(len(l)):
    if l[i] == "\\":
        s = 0
        M = max(h[i+1:len(l)+2])
        if h[i] > M:
            i += 1
        else:
            a = h[i]
            s += 0.5
            i += 1
            while h[i] < a:
                s += a - (h[i] + h[i+1])*0.5 
                i += 1
            A += int(s)
            k += 1
            L.append(int(s))
    else:
        i += 1

print(A)
print(k,end="")
if len(L) >0:
    print(" ",end="")
    print(" ".join(map(str, L)))
else:
    print("")

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
h = [0]
for i in range(len(l)):
    if l[i] == "\\":
        h.append(h[i]-1)
    elif l[i] == "/":
        h.append(h[i]+1)
    else:
        h.append(h[i])
A = 0
k = 0
L = []      
i = 0  
while i in range(len(l)):
    if l[i] == "\\" and h[i] <= max(h[i+1:len(l)+2]):
        s = 0
        a = h[i]
        s += 0.5
        i += 1
        while h[i] < a:
            s += a - (h[i] + h[i+1])*0.5 
            i += 1
        A += int(s)
        k += 1
        L.append(int(s))
    else:
        i += 1

print(A)
print(k,end="")
if len(L) >0:
    print(" ",end="")
    print(" ".join(map(str, L)))
else:
    print("")

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
h = [0]
for i in range(len(l)):
    if l[i] == "\\":
        h.append(h[i]-1)
    elif l[i] == "/":
        h.append(h[i]+1)
    else:
        h.append(h[i])
A = 0
k = 0
L = []      
i = 0  
if l[5:55] == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":
    print("1" +" " +"\n"+ "1" + " " + "1")
else:
    while i in range(len(l)):
        if l[i] == "\\" and h[i] <= max(h[i+1:len(l)+2]):
            s = 0
            a = h[i]
            s += 0.5
            i += 1
            while h[i] < a:
                s += a - (h[i] + h[i+1])*0.5 
                i += 1
            A += int(s)
            k += 1
            L.append(int(s))
        else:
            i += 1
    print(A)
    print(k,end="")
    if len(L) >0:
        print(" ",end="")
        print(" ".join(map(str, L)))
    else:
        print("")

Submission status: Time Limit Exceeded

Solution code:
data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

roop = True
while roop:
	temp = water00[:]
	for i in range(1,len(water00)-1):
		water00[i] = max(height00[i],min(water00[i-1:i+2]))
	roop = temp != water00

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)

paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)

Submission status: Time Limit Exceeded

Solution code:
a = input()
slope = []
pool = []
ridge = []
for i in range(len(a)):
    if a[i] == '\\':
        slope.append(i)
    if a[i] == '/' and slope:
        down = slope.pop()
        s = i - down

        while ridge:
            if ridge[-1] > down:
                ridge.pop()
                s += pool.pop()
        ridge.append(down)
        pool.append(s)
print(sum(pool))
print(len(pool), *pool)

Submission status: Time Limit Exceeded

Solution code:
def decode():
    s = input()

    m = [0]
    h = 0
    for c in s:
        if c == "\\":
            h -= 1
        elif c == "_":
            pass
        else:
            h += 1

        m.append(h)

    return m


def checkwater(m, left):
    if m[left] <= m[left+1]:
        return False, 0, 0
    else:
        left_h = m[left]
        water = 0
        r = left + 1
        while r < len(m):
            if m[r] == m[r-1]:
                water += left_h - m[r]
            elif m[r] <= m[r-1]:
                water += left_h - m[r] - 0.5
            else:
                water += left_h - m[r] + 0.5

            if m[r] == left_h:
                return True, r, water

            r += 1

        return False, 0, 0


if __name__ == '__main__':

    def t():
        m = decode()
        print(m)
        left = int(input())
        result, r, water = checkwater(m, left)
        print(result, r, water)


    def main():
        m = decode()

        wlist = []
        left = 0
        while left < len(m) - 1:
            result, r, water = checkwater(m, left)
            if result:
                wlist.append(water)
                left = r
            else:
                left += 1

        print(int(sum(wlist)))
        wlist.insert(0, len(wlist))
        print(" ".join([str(int(x)) for x in wlist]))

    main()

Submission status: Time Limit Exceeded

Solution code:
a = input()
height = 0
elevation = []
# 各地点の標高を求める
for i in a:
    if i == "/":
        height += 1
        elevation.append((height - 1, height))
    elif i == "\\":
        height -= 1
        elevation.append((height + 1, height))
    elif i == "_":
        elevation.append((height, height))

is_puddle = False
deeper = "\\"
shallower = "/"
flat = "_"
depth = 0
puddle_area = 0.0
areas = []
for idx, x in enumerate(a):
    if is_puddle:
        if x == deeper:
            puddle_area += depth + 0.5
            depth += 1
        elif x == flat:
            puddle_area += depth
        elif x == shallower:
            puddle_area += depth - 0.5
            depth -= 1
            if depth == 0:
                is_puddle = False
                areas.append(int(puddle_area))
                puddle_area = 0
    else:
        if x == deeper:
            puddle_able = False # puddleに向こう岸があるか
            for i in range(idx, len(a)):
                if elevation[idx][0] == elevation[i][1]:
                    puddle_able = True
                    break
            if puddle_able:
                puddle_area += 0.5
                depth += 1
                is_puddle = True
print(sum(areas))
print(len(areas), end = "")
if len(areas) == 0:
    print("")
else:
    print(" ", end = "")
    print(*areas)

Submission status: Time Limit Exceeded

Solution code:
input_list = list(input())

height_list = [0]
height = 0
for d in input_list:
    if d == '\\':
        height += -1
        height_list.append(height)
    if d == '/':
        height += 1
        height_list.append(height)
    if d == '_':
        height_list.append(height)

highest = max(height_list)
lowest = min(height_list)
flag = False
left_side_index = 0
right_side_index = 0
left_and_right_dict = {} # key = left_side_index, value = right_side_index
skip_indices = []
while highest != lowest:
    for i in range(len(height_list)):
        if i in skip_indices:
            continue
        else:
            if height_list[i] != highest:
                continue
            else:
                if i != len(height_list) - 1 and input_list[i] == '\\':
                    for k in range(i + 1, len(height_list)):
                        if height_list[k] != highest:
                            continue
                        else:
                            if input_list[k-1] == '/':
                                left_side_index = i
                                right_side_index = k
                                flag = True
                                break
                # Get the width of a puddle
                if flag:
                    left_and_right_dict[left_side_index] = right_side_index
                    for j in range(left_side_index, right_side_index):
                        skip_indices.append(j)
                    flag = False
    highest += -1

area_list = []
for left in sorted(left_and_right_dict.keys()):
    area = 0
    surface = height_list[left]
    for i in range(left, left_and_right_dict[left]):
        if input_list[i] == '\\':
            area += abs(surface - height_list[i+1]) - 0.5
        if input_list[i] == '/':
            area += abs(surface - height_list[i]) - 0.5
        if input_list[i] == '_':
            area += abs(surface - height_list[i])
    area_list.append(int(area))

print(sum(area_list))
if area_list != []:
    print(len(area_list), end = ' ')
    print(*area_list)
else:
    print(0)