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:
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
c = "".join(l[5:35]) + (" ")
if c == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ":
    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: Wrong Answer

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
c = "".join(l[5:65]) + (" ")
if c == "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ":
    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: Wrong Answer

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:60]) + (" ") != "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ " :
    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: Wrong Answer

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(*pond_areas)

Submission status: Wrong Answer

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

print(a)
print(k, *l)

Submission status: Wrong Answer

Solution code:
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
for t in target:
    # print(now_height,now_area,answer,continued)
    if t == '\\':
        now_height.append(continued)
        now_area.append(0)
    elif t == '_':
        pass
    elif t == '/' and len(now_height) > 0:
        started = now_height.pop()
        temp_area = continued - started
        temp = now_area.pop()
        now_area[-1] += temp_area + temp
        if len(now_height) == 0:
            answer.append(now_area[0])
            now_area = [0]
            continue
    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: Wrong Answer

Solution code:
S = input()
st = [(0, 0, -1)]
cur = 0
for i, c in enumerate(S):
    if c == '/':
        cur += 1
        s = 0
        while st and st[-1][0] == cur-1:
            lev, su, j = st.pop()
            s += su
        if st and st[-1][0] == cur:
            s += i - st[-1][2] - 1
        st.append((cur, s, i))
    elif c == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif c == '_':
        st.append((cur, 0, i))
ans = []
for lev, su, j in st:
    if su > 0:
        ans.append(su)
print(sum(ans))
print(len(ans), *ans)

Submission status: Wrong Answer

Solution code:
S = input()
st = [(0, 0, -1)]
cur = 0; ma = 0
for i, c in enumerate(S):
    if c == '/':
        cur += 1
        s = 0
        while st and st[-1][0] == cur-1 and cur <= ma:
            lev, su, j = st.pop()
            s += su
        if st and st[-1][0] == cur:
            s += i - st[-1][2] - 1
        ma = max(ma, cur)
        st.append((cur, s, i))
    elif c == '\\':
        cur -= 1
        st.append((cur, 0, i))
    elif c == '_':
        st.append((cur, 0, i))
    print(c, st)
ans = []
for lev, su, j in st:
    if su > 0:
        ans.append(su)
print(sum(ans))
print(len(ans), *ans)

Submission status: Wrong Answer

Solution code:
def main():
    line = r"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"

    s1 = []
    s2 = []
    sum = 0
    for i, s in enumerate(line):
        if s == "\\":
            # 谷の位置をスタックに積む
            s1.append(i)
        elif s == "/" and len(s1) > 0:
            # 山で対応する谷があるなら、面積に追加
            j = s1.pop()
            sum += i - j  # 谷から山の距離を水たまりの面積に追加
            # jより前に位置する水たまりの面積を追加
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
            s2.append((j, a))

    print(sum)
    if len(s2) > 0:
        print(len(s2), s2[0][1])
    else:
        print(len(s2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    line = input()

    s1 = []
    s2 = []
    sum = 0
    for i, s in enumerate(line):
        if s == "\\":
            # 谷の位置をスタックに積む
            s1.append(i)
        elif s == "/" and len(s1) > 0:
            # 山で対応する谷があるなら、面積に追加
            j = s1.pop()
            sum += i - j  # 谷から山の距離を水たまりの面積に追加
            # jより前に位置する水たまりの面積を追加
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
            s2.append((j, a))

    print(sum)
    if len(s2) > 0:
        print(len(s2), s2[0][1])
    else:
        print(len(s2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    line = input()
    s1 = []
    s2 = []
    sum = 0
    for i, s in enumerate(line):
        if s == "\\":
            # 谷の位置をスタックに積む
            s1.append(i)
        elif s == "/" and len(s1) > 0:
            # 山で対応する谷があるなら、面積に追加
            j = s1.pop()
            sum += i - j  # 谷から山の距離を水たまりの面積に追加
            # jより前に位置する水たまりの面積を追加
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む
            s2.append((j, a))

    print(sum)
    if len(s2) > 0:
        print(len(s2), end="")
        for x in s2:
            print(f" {x[1]}")
    else:
        print(len(s2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

t=input()
pair=[]
pond=[]
sum=0

for i in range(len(t)):
    if t[i]=="\\" :
        pair.append(i)
    elif t[i]=="/" and len(pair)!=0:
        p1=pair.pop()
        pond.append(i-p1)
        sum+=i-p1

print(sum)
print(len(pond),*pond)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().replace("_", "").strip()):
    if s == "\\":
        li.append([i, 0])
    elif s == "/":
        if li:
            if li[-1][1] == 0:
                li[-1][1] = i - li[-1][0]
            else:
                for j in range(len(li) - 1, -1, -1):
                    if li[j][1] == 0:
                        li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
                        break
ans = []
for a in li:
    if a[1] != 0:
        ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().strip().replace("_", "")):
    if s == "\\":
        li.append([i, 0])
    elif s == "/":
        if li:
            if li[-1][1] == 0:
                li[-1][1] = i - li[-1][0]
            else:
                for j in range(len(li) - 1, -1, -1):
                    if li[j][1] == 0:
                        li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
                        break
ans = []
for a in li:
    if a[1] != 0:
        ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)

Submission status: Wrong Answer

Solution code:
def cross_section_area(data):
    area = 0;
    k = 0;
    section_areas = [];
    section_area = 0;
    stack = [];
    for i in range(len(data)):
        if data[i] == '\\':
            stack.append(i);
        elif data[i] == '/' and len(stack) > 0:
            section_area += i - stack.pop();
            if len(stack) == 0:
                k += 1;
                section_areas.append(section_area);
                area += section_area;
    print(area);
    print(k, *section_areas);

cross_section_area(input());

Submission status: Wrong Answer

Solution code:
def cross_section_area(data):
    area = 0;
    section_areas = [];
    stack = [];
    section_area = 0;
    for i in range(len(data)):
        if data[i] == '\\':
            stack.append(i);
        elif data[i] == '/' and len(stack) > 0:
            section_area += i - stack.pop();
            if len(stack) == 0:
                area += section_area;
                section_areas.append(section_area);
                section_area = 0;
    if section_area > 0:
        section_areas.append(section_area);
        area += section_area;
    print(area);
    print(len(section_areas), *section_areas);

cross_section_area(input());

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

class peak():
    def __init__(self, loc, elevation):
        self.loc = loc
        self.elevation = elevation
        self.next_high = None


def peak_append(peak_list, loc, elevation):
    p = peak(loc, elevation)
    peak_list.append(p)
    return

def peak_set_next_high(peak_list):
    next_high = peak_list[-1]   # last peak
    for i in range(len(peak_list)-2, -1, -1):
        peak_list[i].next_high = next_high
        if peak_list[i].elevation >= next_high.elevation:
            next_high = peak_list[i]


def find_flood(elev_list, peak_list):
    peak_p = peak_list.pop(0)
    next_high = peak_p.next_high
    if not next_high:
        return None, None
    q_elev = next_high.elevation
    p_elev = peak_p.elevation

    if p_elev > q_elev:
        q_offset = next_high.loc
        p_offset = peak_p.loc
        while p_offset < len(elev_list):
            if elev_list[p_offset] == elev_list[q_offset]:
                return p_offset, q_offset
            p_offset += 1
        else:
            return None, None
    else:
        p_offset = peak_p.loc
        q_offset = elev_list.index(p_elev, p_offset+1)
        return p_offset, q_offset
    raise "Logic Error"


def calc_area(p, q, elev_list):
    elev_0 = elev_list[p]
    area = 0

    prev_elev = 0
    for x in range(p, q+1):
        elev = elev_list[x] - elev_0
        area += elev

    return (abs(area))


def adjust_peak_list(q, peak_list):
    while peak_list:
        if peak_list[0].loc >= q:
            return
        peak_list.pop(0)


s = list(sys.stdin.readline().strip())

flood_area = list()
peak_list = list()

ascending = True
elevation = 0
elev_list = list()

for i in range(len(s)):
    elev_list.append(elevation)

    if s[i] == '_':
        pass
    elif s[i] == '/':
        ascending = True
        elevation += 1
    elif s[i] == '\\':
        if ascending:
            peak_append(peak_list, i, elevation)
        ascending = False
        elevation -= 1

elev_list.append(elevation)

if ascending:
    peak_append(peak_list, len(s), elevation)

peak_set_next_high(peak_list)

while peak_list:
    p, q = find_flood(elev_list, peak_list)
    if p == None:
        break
    flood_area.append(calc_area(p, q, elev_list))
    adjust_peak_list(q, peak_list)
    
print(len(flood_area), end=' ')
print(' '.join(map(str, flood_area)))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
data = input()
xmax = len(data)
data_list = list(data)
data_list.reverse()
reverse_data = []
for sig in data_list:
    if sig == "\\":
        reverse_data.append("/")
    elif sig == "/":
        reverse_data.append("\\")
    else:
        reverse_data.append(sig)

reverse_data = "".join(reverse_data)


def partialSqu(h, sig):
    if sig == "\\":
        squ = h + 1/2
        h += 1
    elif sig == "/":
        squ = h - 1/2
        h -= 1
    elif sig == "_":
        squ = h
    return squ, h


x_squ_dict = {}
cnt = 0
sw, x, h, totalSqu = 0, 0, 0, 0
for sig in data: 
    if sw == 0 and sig == "\\":
        sw = 1
    if sw == 1 :
        squ, h = partialSqu(h, sig)
        totalSqu += squ
        
        if h == 0:
            x_squ_dict[x] = totalSqu
            totalSqu = 0
            sw = 0
            cnt += 1

    x += 1

keys = x_squ_dict.keys()
sw, x, h, totalSqu = 0, 0, 0, 0
for sig in reverse_data:
    x += 1
    if sw == 0 and sig == "\\" and (xmax - x) not in keys:
        sw = 1
    if sw == 1 :
        squ, h = partialSqu(h, sig)
        totalSqu += squ            
        if h == 0:
            x_squ_dict[xmax - x] = totalSqu
            totalSqu = 0
            sw = 0
            cnt += 1


print(cnt)
keys = x_squ_dict.keys()
num = len(keys)
keys = list(keys)
keys.sort()
squ_list = []
for key in keys:
    squ_list.append(x_squ_dict[key])
squ_list.insert(0,num)

squ_list = " ".join([str(int(num)) for num in squ_list])
print(squ_list)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = [0]
    for s in stdinput():
        if s == '\\':
            altitutes.append(altitutes[-1] - 1)
        elif s == '_':
            altitutes.append(altitutes[-1])
        elif s == '/':
            altitutes.append(altitutes[-1] + 1)

    edges = []
    n = len(altitutes)
    for i in range(n):
        level = altitutes[i]
        m_idx = i - 1
        for j in range(i - 1, -1, -1):
            if altitutes[j] > level:
                break
            if altitutes[j] == level:
                m_idx = j
                break
        edges.append([m_idx, i])

    areas = []
    begin, end = edges[-1]
    while begin != -1:
        area = calc_area(altitutes, begin, end)
        if area > 0:
            areas.append(area)
        begin, end = edges[begin]
    areas = areas[::-1]

    print(int(sum(areas)))
    print(len(areas))
    if len(areas) > 0:
        print('',end=' ')
        print(*map(int, areas))

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = load_data()

    edges = create_edges(altitutes)

    print(*edges)
    areas = calc_areas(altitutes, edges)

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def load_data():
    A = [0]
    for s in stdinput():
        if s == '\\':
            A.append(A[-1] - 1)
        elif s == '_':
            A.append(A[-1])
        elif s == '/':
            A.append(A[-1] + 1) 
    return A

def create_edges(A):
    edges = []
    n = len(A)
    i = 0
    while i < n - 1:
        j = i + 1
        while  j < n and A[i] > A[j]:
            j += 1
        if j == n:
            j = i + 1
        edges.append([i, j])
        i = j
    return edges

def calc_areas(A, edges):
    areas = []

    for begin, end in edges:
        area = calc_area(A, begin, end)
        if area > 0:
            areas.append(area)
    return areas

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Wrong Answer

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = load_data()

    edges = create_edges(altitutes)

    areas = calc_areas(altitutes, edges)

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def load_data():
    A = [0]
    for s in stdinput():
        if s == '\\':
            A.append(A[-1] - 1)
        elif s == '_':
            A.append(A[-1])
        elif s == '/':
            A.append(A[-1] + 1) 
    return A

def create_edges(A):
    edges = []
    n = len(A)
    w = int(len(A)**0.5)
    for i in range(n):
        level = A[i]
        m_idx = i - 1
        for j in range(i - 1, max(-1, i - 1 - w), -1):
            if A[j] > level:
                break
            if A[j] == level:
                m_idx = j
                break
        edges.append([m_idx, i])
    return edges

def calc_areas(A, edges):
    areas = []
    begin, end = edges[-1]
    while begin != -1:
        area = calc_area(A, begin, end)
        if area > 0:
            areas.append(area)
        begin, end = edges[begin]
    return areas[::-1]
    

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Wrong Answer

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = load_data()

    edges = create_edges(altitutes)

    areas = calc_areas(altitutes, edges)

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def load_data():
    A = [0]
    for s in stdinput():
        if s == '\\':
            A.append(A[-1] - 1)
        elif s == '_':
            A.append(A[-1])
        elif s == '/':
            A.append(A[-1] + 1) 
    return A

def create_edges(A):
    edges = []
    n = len(A)
    w = max(int(len(A)**0.5), 100)
    for i in range(n):
        level = A[i]
        m_idx = i - 1
        for j in range(i - 1, max(-1, i - 1 - w), -1):
            if A[j] > level:
                break
            if A[j] == level:
                m_idx = j
                break
        edges.append([m_idx, i])
    return edges

def calc_areas(A, edges):
    areas = []
    begin, end = edges[-1]
    while begin != -1:
        area = calc_area(A, begin, end)
        if area > 0:
            areas.append(area)
        begin, end = edges[begin]
    return areas[::-1]
    

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Wrong Answer

Solution code:
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    altitutes = load_data()

    edges = create_edges(altitutes)

    areas = calc_areas(altitutes, edges)

    print(int(sum(areas)))
    print(*([len(areas)] + [*map(int, areas)]))

def load_data():
    A = [0]
    for s in stdinput():
        if s == '\\':
            A.append(A[-1] - 1)
        elif s == '_':
            A.append(A[-1])
        elif s == '/':
            A.append(A[-1] + 1) 
    return A

def create_edges(A):
    edges = []
    n = len(A)
    w = max(int(len(A)/2), 100)
    for i in range(n):
        level = A[i]
        m_idx = i - 1
        for j in range(i - 1, max(-1, i - 1 - w), -1):
            if A[j] > level:
                break
            if A[j] == level:
                m_idx = j
                break
        edges.append([m_idx, i])
    return edges

def calc_areas(A, edges):
    areas = []
    begin, end = edges[-1]
    while begin != -1:
        area = calc_area(A, begin, end)
        if area > 0:
            areas.append(area)
        begin, end = edges[begin]
    return areas[::-1]
    

def calc_area(A, begin, end):
    if A[begin] != A[end]:
        return 0
    b_level = A[begin]
    area = 0
    for l1, l2 in zip(range(begin, end), range(begin+1, end + 1)):
        a1 = A[l1]
        a2 = A[l2]
        area += (b_level - a1 + b_level - a2) * 1 / 2
    return area

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Wrong Answer

Solution code:
MAP = {'\\': 1, '_': 0, '/': -1}

input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    this_depth += MAP[c]
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [None] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
        holes.insert(l[j], area)

cnt = 0
sum = 0
holes = [h for h in holes if h and h > 0]
for h in holes:
    cnt += 1
    sum += h
print(sum)
print(" ".join(map(str, [cnt] + holes)))

Submission status: Wrong Answer

Solution code:
MAP = {'\\': 1, '_': 0, '/': -1}

input_str = input()
this_depth = 0
depth_list = [this_depth]
for c in input_str:
    this_depth += MAP[c]
    depth_list.append(this_depth)

min_depth = min(depth_list)
max_depth = max(depth_list)
length = len(depth_list)
holes = [None] * length
for target_depth in range(min_depth, max_depth + 1):
    i = 0
    l = [i for i in range(len(depth_list)) if depth_list[i] == target_depth]
    for j in range(len(l) - 1):
        area = 0
        for k in range(l[j] + 1, l[j + 1]):
            area += depth_list[k] - target_depth
            depth_list[k] = target_depth
        holes.insert(l[j] + 1, area)

cnt = 0
sum = 0
holes = [h for h in holes if h and h > 0]
for h in holes:
    cnt += 1
    sum += h
print(sum)
print(" ".join(map(str, [cnt] + holes)))

Submission status: Wrong Answer

Solution code:
hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = []
chlist = []
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
ch = 0
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    
    if (hh > max(chlist[i:])):
        hh = max(chlist[i:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        f = 1
    elif (ch == hh and chlist[i] == chlist[i-1] + 1):
        f = 0
        s += 1/2
        slist.append(s)
    
    if (f == 1):
        if (hlist[i] == '/'):
            s += (hh - ch + 1/2)
        elif (hlist[i] == '\\'):
            s += (hh - ch - 1/2)
        elif (hlist[i] == '_'):
            s += (hh - ch)
    elif (f == 0):
        s = 0

print(sum(slist))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(int((slist[i])), end = '')
    else:
        print(int((slist[i])), end = ' ')
print()

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

    def get_area(self, pond_height):
        h = pond_height - self.y + 1
        if self.direction == 'f':
            return h
        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.x = 0
        self.height = 0
        self.pond_idx = []
        self.area_list = []

    @property
    def top(self):
        return max([c.y for c in self.cells])
    
    def put(self, c):
        if c == '\\':
            self.height -= 1
            self.cells.append(Cell('d', self.x, self.height))
        elif c == '/':
            self.cells.append(Cell('u', self.x, self.height))
            self.height += 1
        elif c == '_':
            self.cells.append(Cell('f', self.x, self.height))
        self.x += 1

    def adjust_height(self):
        lowest = min([c.y for c in self.cells])
        for c in self.cells:
            c.y -= lowest
    
    def is_pond(self):
        for i_start in range(len(self.cells)):
            c_start = self.cells[i_start]
            if c_start.direction == 'u':
                continue
            if c_start.direction == 'f' and 0 == i_start:
                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':
                        c_start.is_pond = True
                        c_end.is_pond = True
                    elif c_end.direction == 'f':
                        continue
                    break

    def collect_pond_idx(self):
        start = None
        start_c = None
        for c in self.cells:
            if c.is_pond and start == None:
                start = c.x
                start_c = c
            elif not c.is_pond and start != None:
                self.pond_idx.append((start, c.x - 1))
                start = None
                start_c = None
            elif c.is_pond and c.direction == 'd' and c.y == start_c.y:
                self.pond_idx.append((start, c.x - 1))
                start = c.x
                start_c = c

    def get_area(self, idx):
        area = 0
        pond_height = self.cells[idx[0]].y
        for i in range(idx[0], idx[1]+1):
            area += self.cells[i].get_area(pond_height)
        return int(area)

    def get_area_list(self):
        for pond in self.pond_idx:
            self.area_list.append(self.get_area(pond))

    def show(self):
        for i, c in enumerate(self.cells):
            p = 'p' if c.is_pond else ' '
            print('{0:02d}'.format(i) + p + c.char * c.y)

def run():
    area = Area()
    for l in input():
        area.put(l)
    area.adjust_height()
    area.is_pond()
    area.collect_pond_idx()
    area.get_area_list()
    print(sum(area.area_list))
    print(len(area.area_list), ' '.join([str(a) for a in area.area_list]))

if __name__ == '__main__':
    run()