Language: C++

#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{	
	int a[20001][2];
	a[0][0] = 0;
	
	char ch;
	int cnt = 0;
	while (cin >> ch) {
		if (ch == '\\') a[cnt][1] = a[cnt][0] - 1;
		else if (ch == '/') a[cnt][1] = a[cnt][0] + 1;
		else a[cnt][1] = a[cnt][0];
		a[cnt+1][0] = a[cnt][1];
		cnt++;
	}
	
	int edge[2];
	edge[1] = -1;
	int area[10000];
	int k = 0;
	while (1) {
		if (searchEdge(a, cnt, edge)) {
			int area[k] = calcArea(a, edge);
			k++;
		}
		if (edge[1] >= n - 1) break;
	}
	
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += area[i];
	}
	
	cout << sum << endl;
	cout << k << " ";
	for (int i = 0; i < k; i++) {
		cout << area[k];
		if (i < k - 1) cout << " ";
		else cout << endl;
	}
	
	return 0;
}

bool searchEdge(const int a[], int n, int edge[])
{	
	edge[0] = edge[1] + 1;
	for (int i = edge[0]; i < n; i++) {
		if (a[i][1] - a[i][0] == -1) {
			edge[0] = i;
			break;
		}
	}	
	if (i >= n) return false;
	
	int height = a[edge[0]][0];
	edge[1] = edge[0];	
	for (int i = edge[1]; i < n; i++) {
		if (a[i][1] == height) {
			edge[1] = i;
			break;
		}
	}
	if (i >= n) return false;
	
	return true;
}

int calcArea(const int a[], const int edge[])
{
	int max = a[edge[0][0]];
	int area = 0;
	for (int i = edge[0]; i <= edge[1]; i++) {
		if (a[i][0] < max || a[i][1] < max) {
			area += (-(a[i][0] - max));
			area += (-(a[i][1] -a[i][0]) / 2);
		}
	}
	
	return area;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:21: error: 'searchEdge' was not declared in this scope
   25 |                 if (searchEdge(a, cnt, edge)) {
      |                     ^~~~~~~~~~
a.cc:26:39: error: 'calcArea' was not declared in this scope
   26 |                         int area[k] = calcArea(a, edge);
      |                                       ^~~~~~~~
a.cc:29:32: error: 'n' was not declared in this scope
   29 |                 if (edge[1] >= n - 1) break;
      |                                ^
a.cc: In function 'bool searchEdge(const int*, int, int*)':
a.cc:52:25: error: invalid types 'const int[int]' for array subscript
   52 |                 if (a[i][1] - a[i][0] == -1) {
      |                         ^
a.cc:52:35: error: invalid types 'const int[int]' for array subscript
   52 |                 if (a[i][1] - a[i][0] == -1) {
      |                                   ^
a.cc:57:13: error: 'i' was not declared in this scope
   57 |         if (i >= n) return false;
      |             ^
a.cc:59:32: error: invalid types 'const int[int]' for array subscript
   59 |         int height = a[edge[0]][0];
      |                                ^
a.cc:62:25: error: invalid types 'const int[int]' for array subscript
   62 |                 if (a[i][1] == height) {
      |                         ^
a.cc:67:13: error: 'i' was not declared in this scope
   67 |         if (i >= n) return false;
      |             ^
a.cc: In function 'int calcArea(const int*, const int*)':
a.cc:74:28: error: invalid types 'const int[int]' for array subscript
   74 |         int max = a[edge[0][0]];
      |                            ^
a.cc:77:25: error: invalid types 'const int[int]' for array subscript
   77 |                 if (a[i][0] < max || a[i][1] < max) {
      |                         ^
a.cc:77:42: error: invalid types 'const int[int]' for array subscript
   77 |                 if (a[i][0] < max || a[i][1] < max) {
      |                                          ^
a.cc:78:40: error: invalid types 'const int[int]' for array subscript
   78 |                         area += (-(a[i][0] - max));
      |                                        ^
a.cc:79:40: error: invalid types 'const int[int]' for array subscript
   79 |                         area += (-(a[i][1] -a[i][0]) / 2);
      |                                        ^
a.cc:79:49: error: invalid types 'const int[int]' for array subscript
   79 |                         area += (-(a[i][1] -a[i][0]) / 2);
      |                                                 ^