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: Accepted

Solution code:

def search_down_index(index, depthes, L):
    "index?????????????§??????????????????¨?????????????????????"
    for i in range(index, L - 1):
        if depthes[i] > depthes[i + 1]:
            return i
    return None

def search_down_index_reverse(index, depthes, L):
    "index?????????????§??????????????????¨?????????????????????"
    for i in range(index, -1, -1):
        if depthes[i] > depthes[i - 1]:
            return i
    return None

def search_up_index(index, depthes, L):
    "index?????????????§??????????????????¨?????????????????????"
    for i in range(index, L - 1):
        if depthes[i] < depthes[i + 1]:
            return i
    return None

def search_up_index(index, depthes, L):
    "index?????????????§??????????????????¨?????????????????????"
    for i in range(index, -1, -1):
        if depthes[i] < depthes[i + 1]:
            return i
    return None

def search_index_by_depth(index, depth, depthes, L):
    for i in range(index, L):
        if depthes[i] == depth:
            return i
    return None

def search_index_by_depth_reverse(index, depth, depthes, L):
    for i in range(index, -1, -1):
        if depthes[i] == depth:
            return i
    return None

def calc_area(begin_index, end_index, depthes):
    init_depth = depthes[begin_index]
    area = 0
    for i in range(begin_index, end_index):
        d1 = depthes[i]
        d2 = depthes[i + 1]
        if d1 > d2:
            area += (init_depth - d2 - 0.5)
        elif d1 == d2:
            area += init_depth - d1
        else:
            area += (init_depth - d1 - 0.5)
    return area

depthes = []
depth = 0
depthes.append(0)
for c in input():
    if c == "/":
        depth += 1
    elif c == "?\" or c == "\\":
        depth += -1
    depthes.append(depth)

L = len(depthes)
pond_ranges = []
stack = []
left_begin_index = search_down_index(0, depthes, L)
right_begin_index = search_down_index_reverse(L - 1, depthes, L)
while left_begin_index != None and right_begin_index != None and left_begin_index < right_begin_index:
    dl = depthes[left_begin_index]
    dr = depthes[right_begin_index]
    if dl < dr:
        left_end_index = search_index_by_depth(left_begin_index + 1, dl, depthes, L)
        pond_ranges.append((left_begin_index, left_end_index))
        left_begin_index = search_down_index(left_end_index, depthes, L)
    else:
        right_end_index = search_index_by_depth_reverse(right_begin_index - 1, dr, depthes, L)
        pond_ranges.append((right_end_index, right_begin_index))
        right_begin_index = search_down_index_reverse(right_end_index, depthes, L)

pond_ranges.sort()

k = len(pond_ranges)
areas = []
for r in pond_ranges:
    areas.append(int(calc_area(r[0], r[1], depthes)))
print(sum(areas))
if len(pond_ranges) == 0:
    print(0)
else:
    print(str(k), " ".join(map(str, areas)))

Submission status: Accepted

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_tops = list(filter(lambda top:cur_top[0] <= top[0], top_list[i + 1:]))
        #print(next_tops)
        if next_tops:
            next_top = next_tops[0]
            puddles.append((cur_top[1], next_top[1]))
            i = top_list.index(next_top)
        else:
            cur_top[0] -= 1
            cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1
    #print(hight_list)
    #print(top_list)
    #print(puddles)
    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: Accepted

Solution code:
def analyze_map(data):
    S1 = []  # ?°´????????????????§?????????£?????¨
    S2 = []  # ?°´??????????????¢?????£?????¨

    area = 0
    for i, p in enumerate(data):
        if p == '\\':
            S1.append(i)  # '\'?????????????????????????¨???¶
        elif p == '/':
            if S1:
                pos = S1.pop()
                area = (i - pos)
                while S2 and S2[-1][0] > pos:
                    sub_pos, sub_area = S2.pop()
                    area += sub_area
                S2.append((pos, area))
    return S2


if __name__ == '__main__':
    # ??????????????\???
    #data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
    #data = '\\\\///\\_/\\/'
    data = input()

    # ???????????????
    results = analyze_map(data)

    # ???????????¨???
    # print(results)
    total_area = sum([area for pos, area in results])
    if total_area:
        print(total_area)
        valid_areas = [area for start, area in results if area > 0]
        print('{0} {1}'.format(len(valid_areas), ' '.join(map(str, valid_areas))))
    else:
        print('0\n0')

Submission status: Accepted

Solution code:
from collections import deque

input_list = input()
area = 0
depth_arr = deque()
area_arr = deque()

for i, input_str in enumerate(input_list):
    if "\\" == input_str:
        depth_arr.append(i)
    elif "/" == input_str:
        if len(depth_arr):
            position = depth_arr.pop()
            pool = i - position
            area += pool

            while len(area_arr):
                pre_position, pre_pool = area_arr.pop()
                if position <= pre_position:
                    pool += pre_pool
                else:
                    area_arr.append((pre_position, pre_pool))
                    break
            area_arr.append((position, pool))

areas = 0
for pos, pool in area_arr:
    areas += pool
print(areas)
print(len(area_arr), *[list[1] for list in area_arr])

Submission status: Accepted

Solution code:
high_water_marks = {}
areas = []

depth = 0
offset = 0
for i in input():
  if i == "/":
    depth -= 1
    if depth in high_water_marks:
      hwm = high_water_marks[depth]
      new_area = [hwm, offset - hwm]
      while len(areas) > 0 and areas[-1][0] > hwm:
        a = areas.pop()
        new_area[1] += a[1]
      areas.append(new_area)
  elif i == "_":
    pass
  else:
    high_water_marks[depth] = offset
    depth += 1

  offset += 1

total = 0
for a in areas: total += a[1]
print(total)
sizes = [a[1] for a in areas]
sizes.insert(0, len(areas))
print(" ".join(map(str, sizes)))

Submission status: Accepted

Solution code:
"""
O(n^2)??????????§£???
"""

danmen = input()
depth = []
tmp_dpt = 0

for line in danmen:
    depth.append(tmp_dpt)

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

# len(depth) = len(danmen) + 1?????¨???
depth.append(tmp_dpt)

# print(depth)

i = 0
L = []

while i < len(danmen):
    if len(set(danmen[i:])) == 1:
        break

    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: Accepted

Solution code:
# l = open('input.txt').readline()
l = input()

k = 0
S1, S2 = [], []
for i in range(len(l)):
    if l[i] == '\\':
        S1.append(i)
    elif l[i] == '/' and S1:
        j = S1.pop()
        a = i - j
        k += i - j

        while S2 and S2[-1][0] > j:
            a += S2.pop()[1]
        S2.append((j, a))
print(k)
print(len(S2), *(a for j, a in S2))

Submission status: Accepted

Solution code:

danmen = input()
down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] > left:
                edge.pop()
                area += pool.pop()
            else:
                break

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Submission status: Accepted

Solution code:

danmen = input()

down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] < left:
                break
            edge.pop()
            area += pool.pop()

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Submission status: Accepted

Solution code:
def main():
    sectionalview = input()
    stack = []
    a_surface = 0
    surfaces = []
    for cindex in range(len(sectionalview)):
        if sectionalview[cindex] == "\\":
            stack.append(cindex)
        elif sectionalview[cindex] == "/" and 0 < len(stack):
            if 0 < len(stack):
                left_index = stack.pop()
                a = cindex - left_index
                a_surface += a
                while 0 < len(surfaces):
                    if left_index < surfaces[-1][0]:
                        a += surfaces.pop()[1]
                    else:
                        break
                surfaces.append((cindex, a))
    t = [i[1] for i in surfaces]
    print(sum(t))
    print(" ".join(map(str, [len(t)] + t)))

if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Submission status: Accepted

Solution code:
g = input()
l = []
q = []
n = 0
for x in range(len(g)):
    if g[x] == '\\':
        if n:
            l.append(n)
            n = 0
            if q:
                q.append(-1)
        q.append(x)
    elif g[x] == '/':
        if q:
            while True:
                p = q.pop()
                if p == -1:
                    n += l.pop()
                else:
                    break
            n += x-p
    else:
        pass
if n:
    l.append(n)
for j in range(l.count(0)):
    l.remove(0)
print(sum(l))
print(len(l), *l)

Submission status: Accepted

Solution code:
s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
    if x=='\\':a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    input_string = raw_input().strip()
    down_positions = []
    ponds = []
    for index, value in enumerate(input_string):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            # candidate_pond = []
            area2 = 0
            while ponds and left < ponds[-1][0]:
               # candidate_pond.append(ponds.pop(-1))
               area2 += ponds.pop(-1)[1]

            # new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            new_pond = (left, area + area2)
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():
    down_positions = []
    ponds = []
    for index, value in enumerate(raw_input()):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_area = 0
            while ponds and left < ponds[-1][0]:
               candidate_area += ponds.pop(-1)[1]

            # new_pond = (left, area + candidate_area)
            ponds.append((left, area + candidate_area))
            # ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
down_positions = []
ponds = []
for index, value in enumerate(raw_input()):
    if value == '\\':
        down_positions.append(index)
    elif value == '/' and down_positions:
        right = index
        left = down_positions.pop()
        area = right - left
        candidate_area = 0
        while ponds and left < ponds[-1][0]:
           candidate_area += ponds.pop(-1)[1]

        ponds.append((left, area + candidate_area))

print sum(x[1] for x in ponds)
print len(ponds), 
for pond in ponds:
    print pond[1],

Submission status: Accepted

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 "".join(l[5:65]) + (" ") == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " and "".join(l[1:61]) + (" ") != "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " :
    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: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os


s = input().strip()

S1 = []  # sum of pond
S2 = []  # each pond
area = 0

for i, c in enumerate(s):
    if c == '\\':
        S1.append(i)
    elif c == '_':
        pass
    elif c == '/' and S1:
        j = S1.pop(-1)
        area += i - j

        # for each pond
        # ?????????????????????????????´???, pond?????±??????????????????
        pond_sum = i - j  # ???????????????????????¢???
        while S2 and S2[-1][0] > j:
            pond_sum += S2[-1][1]
            S2.pop(-1)
        S2.append([j, pond_sum])

pond_areas = []
for data in S2:
    pond_areas.append(data[1])

# answer
print(area)
print(len(pond_areas), *pond_areas)

Submission status: Accepted

Solution code:
# coding:utf-8
danmen = input()
S1 = []
S2 = []
area = 0 # ?????????????°´???????????¢???

for i, line in enumerate(danmen):
    if line == '\\':
        S1.append(i)
    elif S1 and line == '/':
        loc = S1.pop()
        area += i-loc

        pond_sum = i-loc
        while S2 and S2[-1][0] > loc:
            pond_sum += S2[-1][1]
            S2.pop()

        S2.append([loc,pond_sum])


print(area)
print(len(S2),*(a for j,a in S2))

Submission status: Accepted

Solution code:
from __future__ import print_function
from collections import deque

q = deque()
n = 0
d = 0
r = {}
mind = 0
maxd = 0

for x, c in enumerate(raw_input()):
    if c == "\\":
        d += 1
        maxd = max(maxd, d)
        q.append(x)
        n += 1
    elif c == "/":
        d -= 1
        mind = min(mind, d)
        if n == 0:
            continue
        x0 = q.pop()
        n -= 1
        s = x - x0
        if (d + 1) in r:
            while r[d + 1] and r[d + 1][-1][0] > x0:
                s += r[d + 1].pop()[1]
        if d not in r:
            r[d] = deque()
        r[d].append((x, s))

a = 0
k = 0
l = []
for d in xrange(mind, maxd):
    if d in r:
        for x, s in r[d]:
            a += s
            k += 1
            l.append((x, s))
l.sort()

print(a)
print(k, *(s for x, s in l))

Submission status: Accepted

Solution code:
def main():
    SS = 0
    s1 = []
    s2 = []
    l = raw_input()
    for b in range(len(l)):
        c = l[b]
        if c == '\\':
            s1.append(b)
        elif c == "/":
            if not len(s1) == 0:
                a  = s1.pop()
                s  = b-a
                SS += s
                while not len(s2) == 0:
                    sigma,alpha,beta = s2.pop()
                    if alpha>a and beta<b:
                        s = s + sigma
                    else:
                        s2.append([sigma,alpha,beta])
                        break
                s2.append([s,a,b])
        
    print SS
    print len(s2),
    for item in s2[:-1]:
        print item[0],
    if not len(s2) == 0:
        print s2[-1][0]


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
    # print(now_height,depth_list,now_area,answer,continued)
    if t == '\\':
        now_height.append(continued)
        depth_list.append(depth)
        now_area.append(0)
        depth -= 1
    elif t == '_':
        pass
    elif t == '/' and len(now_height) > 0:
        depth += 1
        started = now_height.pop()
        temp_area = continued - started
        # print(depth_list[-1],depth)
        now_area[-1] += temp_area
        if depth > depth_list[-1]:
            while depth > depth_list[-1]:
                temp = now_area.pop()
                now_area[-1] += temp
                depth_list.pop()
        if len(now_height) == 0 or depth == depth_list[0]:
            answer.append(sum(now_area))
            now_area = [0]
            depth_list = []
    continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer)

Submission status: Accepted

Solution code:
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
    # print(now_height,depth_list,now_area,answer,continued)
    if t == '\\':
        now_height.append(continued)
        depth_list.append(depth)
        now_area.append(0)
        depth -= 1
    elif t == '_':
        pass
    elif t == '/' and len(now_height) > 0:
        depth += 1
        started = now_height.pop()
        temp_area = continued - started
        # print(depth_list[-1],depth)
        now_area[-1] += temp_area
        if depth > depth_list[-1]:
            while depth > depth_list[-1]:
                temp = now_area.pop()
                now_area[-1] += temp
                depth_list.pop()
    continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer)

Submission status: Accepted

Solution code:
def cross_section_diagram():
	down = []
	edge = []
	pool = []

	for i, c in enumerate(input()):
		if c == '\\':
			down.append(i)
		elif c == '/' and down:
			left = down.pop()
			area = i - left

			while edge:
				if edge[-1] < left:
					break
				edge.pop()
				area += pool.pop()

			edge.append(left)
			pool.append(area)

	print(sum(pool))
	print(len(pool), *pool)

if __name__ == '__main__':
	cross_section_diagram()

Submission status: Accepted

Solution code:
def cross_section_diagram():
	down = []
	edge = []
	pool = []

	for i, c in enumerate(input()):
		if c == '\\':
			down.append(i)
		elif c == '/' and down:
			left = down.pop()
			area = i - left

			while edge:
				if edge[-1] > left:
					edge.pop()
					area += pool.pop()
				else:
					break

			edge.append(left)
			pool.append(area)

	print(sum(pool))
	print(len(pool), *pool)

if __name__ == '__main__':
	cross_section_diagram()

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code
stack1=[] # \????????????????????????????¨???¶
stack2=[] #???stack1???????????????????????¨??¢???????¨???¶
sum=0
for i,c in enumerate(input()):
    if c =="\\":
        stack1.append(i)
    elif c=="/":
        if stack1:
            poped = stack1.pop()
            res = i-poped
            sum += res
            while stack2 and stack2[-1][0]>poped:
                res+=stack2.pop()[1]
            stack2.append([poped,res])
    
print(sum)
print(len(stack2),*(a for j,a in stack2))

Submission status: Accepted

Solution code:
#\??¨?????????????´???????????????????
RL=[]
#?°´??????????????????????????¨??¢??????????´???????????????????
SL=[]

#\?????????RL????????????????????????????????????
def downer(index):
    RL.append(index)

#/?????????RL??????\????????????????????¢???????¨???????SL???????´?
def upper(index):
    if len(RL) > 0:
        p = RL.pop()
        q = index
        s = q - p
        if len(SL) > 0:
            QL = SL[::-1]
            for i in QL:
                if i[0] > p:
                    s += SL.pop()[1]
                else:
                    break
            SL.append([p, s])
        else: SL.append([p, s])
    else:return

L = input()
index = 0
for i in L:
    if i =="\\":
        downer(index)
        index += 1
    elif i =="/":
        upper(index)
        index += 1
    else:
        index += 1
AL =[]
for i in SL:
    AL.append(i[1])
print(str(sum(AL)))
if len(AL) == 0:
    print(len(AL))
else:
    print(len(AL),end=" ")
    print(" ".join(map(str,AL)))

Submission status: Accepted

Solution code:
# coding=utf-8

S1 = []
S2 = []
total_square = 0
j = 0

input = list(input())

for i, val in enumerate(input):
    sq = 0
    if val == '\\':
        S1.append(i)
    elif val == '/':
        if len(S1) > 0:
            j = S1.pop()
            total_square += (i - j)
            if len(S2) > 0:
                if (S2[-1][0] > j):
                    while (S2[-1][0] > j):
                        poped = S2.pop()
                        sq += poped[1]
                        if len(S2) == 0:
                            break
                    S2.append([j, sq + (i-j)])
                else:
                    S2.append([j, (i-j)])
            else:
                S2.append([j, i-j])

print(total_square)
print(len(S2), end = "")
for data in S2:
    print(' ' + str(data[1]), end = "")
print()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    inp = input()
    a = []
    ans = []
    total = 0
    for i in range(len(inp)):
        if inp[i] == "\\":
            a.append(i)
        elif inp[i] == "/":
            if len(a) != 0:
                x = a.pop()
                d = i - x
                total += d
                while len(ans) != 0 and ans[-1][0] > x:
                    d += ans[-1][1]
                    ans.pop()
                ans.append([x, d])
    print(total)
    if total == 0:
        print(0)
    else:
        print(str(len(ans))+" "+(" ".join(map(str, [x[1] for x in ans]))))

Submission status: Accepted

Solution code:
s = input()
depth_list = [0]*len(s)
max_depth = [0]*len(s)
d = 0
for i, c in enumerate(s):
    if c == "\\":
        d -= 1
    elif c == "/":
        d += 1
    depth_list[i] = d

m_d = d
for i in range(len(s)-1, -1, -1):
    if s[i] == "\\":
        d += 1
    elif s[i] == "/":
        d -= 1
    max_depth[i] = m_d
    m_d = max(m_d, d)

d = 0
m_d = 0
water = 0
puddles = [0]
for i, n in enumerate(depth_list):
    up = min(m_d, max_depth[i])
    if d < up and d != n or d == up and d > n:
        water += 0.5
    if d < n:
        d = n
    water += max(0, up - d)
    d = n
    m_d = max(m_d, d)

    if d == up and sum(puddles) < int(water):
        m_d = d
        puddles.append(int(water - sum(puddles)))
print(int(water))
print(str(len(puddles)-1)+(" "if len(puddles)>1 else "")+" ".join([str(n) for n in puddles[1:]]))

Submission status: Accepted

Solution code:
A = 0
left = []
Lake = []
s = input()
for i in range(len(s)):
    if s[i] == "\\":
        left.append(i)
    elif s[i] == "/":
        if len(left) > 0:
            w = left.pop()
            goukei = i - w
            A += goukei
            for i in range(len(Lake)-1,-1,-1):
                if Lake[i][0] > w:
                    x = Lake.pop()
                    goukei += x[1]
            Lake.append([w, goukei])
print(A)
if len(Lake) == 0:
    print(0)
else:
    print(len(Lake),end=" ")
for i in range(len(Lake)):
    if i == len(Lake) - 1:
        print(Lake[i][1])
    else:
        print(Lake[i][1],end=" ")

Submission status: Accepted

Solution code:
S=input()
sum_a = 0
index = []
area = []
pos = []
for i,s in enumerate(S):
    if(s=="\\"):
        index.append(i)
    if(s=="/" and index):
        tmp = i - index[-1]
        sum_a += tmp
        pop = index.pop()
        while pos and pop < pos[-1]:
            tmp += area.pop()
            pos.pop()
        pos += [pop]
        area += [tmp]
        
print(sum_a)
print(len(area),*(area))

Submission status: Accepted

Solution code:
import sys

class Area:
    def __init__(self, start, end, area):
        self.start = start
        self.end = end
        self.area = area
    def addArea(self, area):
        self.area += area

if __name__ == "__main__":
    line = sys.stdin.readline().strip()
    
    area_stack = []
    field_stack = []
    
    for i in range(0, len(line)):
        c = line[i]
        if (c == "\\"):
            field_stack.append((c, i))
        elif (c == "/"):
            if len(field_stack) == 0:
                continue
            cc = field_stack.pop()
            current_area = Area(cc[1], i, (i - cc[1]))
            if len(area_stack) == 0:
                area_stack.append(current_area)
                continue
            prev_area = area_stack.pop()
            flag = True
            while (prev_area.start > current_area.start) and (prev_area.end < current_area.end):
                current_area.addArea(prev_area.area)
                if len(area_stack) == 0:
                    flag = False
                    break
                prev_area = area_stack.pop()
            if flag:
                area_stack.append(prev_area)
            area_stack.append(current_area)
    print str(reduce(lambda x, y: x + y, map(lambda x: x.area, area_stack), 0))
    s = ""
    s += str(len(area_stack)) + " "
    for item in area_stack:
        s += str(item.area) + " "
    s = s.strip()
    print s

Submission status: Accepted

Solution code:
s = input()

st = []
leftn = 0

def pushv(s, x):
        tmp = s.pop()
        tmpsum = 0
        while tmp[0] != 'left':
                tmpsum += tmp[1]
                tmp = s.pop()
        else:
                tmpsum += x - tmp[1]
                s.append(('v', tmpsum))

for x in range(len(s)):
        if s[x] == '\\':
                st.append(('left', x))
                leftn += 1
        elif s[x] == '/':
                if leftn != 0:
                        pushv(st, x)
                        leftn -= 1

st = [x[1] for x in st if x[0] == 'v']

if len(st) != 0:
       print(sum(st))
       print(len(st), ' '.join([str(x) for x in st]))
else:
      print(0)
      print(0)

Submission status: Accepted

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
forward = 1
while roop:
	temp = water00[:]
	for i in range(1,len(water00)-1)[::forward]:
		water00[i] = max(height00[i],min(water00[i-1:i+2]))
	roop = temp != water00
	forward *= -1

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)