alexjercan/bugnet huggingface dataset:
Problem p02266 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
 */
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string line;
  getline(cin, line);

  stack<int> pond;
  stack<pair<int, int>> areastack;
  int total = 0;
  for (int i = 0; i < line.length(); i++) {
    if (line[i] == '\\\\') {
      pond.push(i);
    } else if (pond.size() > 0 && line[i] == '/') {
      int j = pond.top();
      pond.pop();
      int a = i - j;
      total += a;
      while (areastack.size() > 0 && areastack.top().first > j) {
        a += areastack.top().second;
        areastack.pop();
      }
      areastack.push(make_pair(j, a));
    }
  }

  vector<int> areas(areastack.size());
  int index = 0;
  while (areastack.size() > 0) {
    areas[index++] = areastack.top().second;
    areastack.pop();
  }

  cout << total << endl;
  cout << areas.size();
  for (auto it = areas.crbegin(); it != areas.crend(); it++) {
    cout << ' ' << *it;
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
 */
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  string line;
  getline(cin, line);

  int level = 0;
  vector<int> levels(line.length() + 1); // level at the point
  levels[0] = level;
  map<int, pair<int, int>> areas; // start, end, area
  map<int, int> working;          // start, workarea
  for (int i = 0; i < line.length(); i++) {
    working.insert(map<int, int>::value_type(i, 0));

    set<int> delist;
    switch (line[i]) {
    case '\\\\':
      level--;
      for (auto &it : working) {
        working[it.first] += 2 * (levels[it.first] - level) - 1;
      }
      break;
    case '_':
      for (auto &it : working) {
        if (levels[it.first] == level) {
          delist.insert(it.first);
        }
        working[it.first] += 2 * (levels[it.first] - level);
      }
      break;
    case '/':
      level++;
      for (auto &it : working) {
        if (levels[it.first] <= level) {
          delist.insert(it.first);
        }
        if (levels[it.first] < level)
          break;
        working[it.first] += 2 * (levels[it.first] - level) + 1;
      }
      break;
    }
    for (auto &it : delist) {
      if (working[it] > 0)
        areas.insert(map<int, pair<int, int>>::value_type(
            it, make_pair(i + 1, working[it] / 2)));
      working.erase(it);
    }
    levels[i + 1] = level;
  }

  vector<int> k;
  auto it = areas.cbegin();
  int next;
  int total = 0;
  while (it != areas.end()) {
    next = it->second.first;
    total += it->second.second;
    k.push_back(it->second.second);
    while (it != areas.end() && it->first < next)
      advance(it, 1);
  }

  cout << total << endl;
  cout << k.size();
  for (auto &it : k) {
    cout << ' ' << it;
  }
  cout << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
#define S second
#define F first
#define psb push_back
#define pob pop_back
#define mpa make_pair
int main() {
  stack<int> place;
  vector<Pi> sub;
  string s;
  int flag = 0, flug = 0;
  int cnt = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\\\\') {
      place.push(i);
      cnt++;
      flag = true;
    } else if (s[i] == '/') {
      cnt--;
      if (flag)
        flug = true;
      if (place.empty())
        sub.psb(mpa(0, cnt));
      else {
        int p = place.top();
        place.pop();
        int size = sub.size();
        size--;
        int sum = i - p;
        while (~size && sub[size].S > cnt) {
          sum += sub[size].F;
          sub.pob();
          size--;
        }
        sub.psb(mpa(sum, cnt));
      }
    }
  }
  int water = 0;
  cnt = 0;
  for (int i = 0; i < sub.size(); i++) {
    if (sub[i].F) {
      cnt++;
      water += sub[i].F;
    }
  }
  cout << water << endl;
  cout << cnt;
  if (!flug || sub.empty())
    cout << endl;
  else
    cout << " ";
  int i;
  int sz = -1;
  for (i = sub.size() - 1; i >= 0; i--) {
    if (sub[i].F) {
      sz = i;
      break;
    }
  }
  for (i = 0; i <= sz - 1; i++) {
    if (sub[i].F)
      cout << sub[i].F << " ";
  }
  if (~sz && sub[i].F)
    cout << sub[i].F << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
#define S second
#define F first
#define psb push_back
#define pob pop_back
#define mpa make_pair
int main() {
  stack<int> place;
  vector<Pi> sub;
  string s;
  int cnt = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\\\\') {
      place.push(i);
      cnt++;
    } else if (s[i] == '/') {
      cnt--;
      if (place.empty())
        sub.psb(mpa(0, cnt));
      else {
        int p = place.top();
        place.pop();
        int size = sub.size();
        size--;
        int sum = i - p;
        while (~size && sub[size].S > cnt) {
          sum += sub[size].F;
          sub.pob();
          size--;
        }
        sub.psb(mpa(sum, cnt));
      }
    }
  }
  int water = 0;
  cnt = 0;
  for (int i = 0; i < sub.size(); i++) {
    if (sub[i].F) {
      cnt++;
      water += sub[i].F;
    }
  }
  cout << water << endl;
  cout << cnt << " ";
  int i;
  int sz = 0;
  for (i = sub.size() - 1; i >= 0; i--) {
    if (sub[i].F) {
      sz = i;
      break;
    }
  }
  for (i = 0; i <= sz - 1; i++) {
    if (sub[i].F)
      cout << sub[i].F << " ";
  }
  if (~sz)
    cout << sub[i].F << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
int main() {
  std::stack<int> S1;
  std::stack<std::pair<int, int>> S2;
  char c;
  int sum = 0;
  for (int i = 0; std::cin >> c; i++) {
    if (c == '\\\\')
      S1.push(i);
    else if (c == '/' && S1.size() > 0) {
      int tmp1 = S1.top();
      S1.pop();
      sum += i - tmp1;
      int tmp2 = i - tmp1;
      while (S2.size() > 0 && S2.top().first > tmp1)
        tmp2 += S2.top().second, S2.pop();
      S2.push(std::make_pair(tmp1, tmp2));
    }
  }
  std::vector<int> out;
  std::cout << sum << std::endl;
  sum = 0;
  while (S2.size() > 0)
    out.push_back(S2.top().second), S2.pop();
  std::reverse(out.begin(), out.end());
  std::cout << out.size();
  for (int i = 0; i < out.size(); i++) {
    sum += out[i];
    std::cout << " " << out[i];
  }
  std::cout << std::endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
int main() {
  std::stack<int> S1;
  std::stack<std::pair<int, int>> S2;
  char c;
  int sum = 0;
  for (int i = 0; std::cin >> c; i++) {
    if (c == '\\\\')
      S1.push(i);
    else if (c == '/' && S1.size() > 0) {
      int tmp1 = S1.top(), tmp2 = S2.top().second;
      S1.pop();
      sum += i - tmp1;
      while (S2.size() > 0 && S2.top().first > tmp1)
        tmp2 += S2.top().second;
      S2.pop();
      S2.push(std::make_pair(tmp1, tmp2));
    }
  }
  std::vector<int> out;
  std::cout << sum << std::endl;
  sum = 0;
  while (S2.size() > 0)
    out.push_back(S2.top().second), S2.pop();
  std::reverse(out.begin(), out.end());
  std::cout << out.size();
  for (int i = 0; i < out.size(); i++) {
    sum += out[i];
    std::cout << " " << out[i];
  }
  std::cout << std::endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int depth[20001], d = 0;
  string str;
  vector<int> area, b;
  cin >> str;

  for (int i = 0; i < 20000; i++) {
    depth[i] = -9999999;
  }
  depth[0] = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '\\\\') {
      d -= 1;
    } else if (str[i] == '\\/') {
      d += 1;
      for (int j = i - 1; j >= 0; j--) {
        if (depth[j] == d) {
          if (b.size() != 0 && b.back() > j) {
            int a = 0;
            while (b.size() != 0 && b.back() > j) {
              a += area.back();
              area.pop_back();
              b.pop_back();
            }
            area.push_back(i - j + a);
            b.push_back(j);
          } else {
            area.push_back(i - j);
            b.push_back(j);
          }
          break;
        }
      }
    }
    depth[i + 1] = d;
  }
  /*
  for (int i = 0; depth[i] != -9999999; i++) {
          cout << depth[i] << endl;
  }
  */
  int allsize = 0;
  for (int i = 0; i < area.size(); i++) {
    allsize += area[i];
  }
  cout << allsize << endl;
  cout << area.size();
  for (int i = 0; i < area.size(); i++) {
    cout << " " << area[i];
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int calcArea(int depth[], int d, int index) {
  for (int i = index; i >= 0; i--) {
    if (depth[i] == d) {
    }
  }
}

int main(void) {
  int depth[20000], d = 0;
  string str;
  vector<int> area, b;
  cin >> str;

  for (int i = 0; i < 20000; i++) {
    depth[i] = -9999999;
  }
  depth[0] = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '\\\\') {
      d -= 1;
    } else if (str[i] == '\\/') {
      d += 1;
      for (int j = i - 1; j >= 0; j--) {
        if (depth[j] == d) {
          if (b.size() != 0 && b.back() > j) {
            int a = 0;
            while (b.size() != 0 && b.back() > j) {
              a += area.back();
              area.pop_back();
              b.pop_back();
            }
            area.push_back(i - j + a);
            b.push_back(j);
          } else {
            area.push_back(i - j);
            b.push_back(j);
          }
          break;
        }
      }
    }
    depth[i + 1] = d;
  }
  /*
  for (int i = 0; depth[i] != -9999999; i++) {
          cout << depth[i] << endl;
  }
  */
  int allsize = 0;
  for (int i = 0; i < area.size(); i++) {
    allsize += area[i];
  }
  cout << allsize << endl;
  cout << area.size();
  for (int i = 0; i < area.size(); i++) {
    cout << " " << area[i];
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
// #include<cmath>
using namespace std;

int main(void) {
  int i = 0, sum = 0, k = 0, a, b;
  string s;
  stack<int> S;
  stack<pair<int, int>> A;
  cin >> s;
  while (i != s.size()) {
    switch (s[i]) {
    case '\\\\':
      S.push(i);
      break;
    case '_':
      i++;
      continue;
    case '/':
      if (!S.empty()) {
        sum += i - S.top();
        A.push(make_pair(S.top(), i - S.top()));
        S.pop();
      }
    }
    i++;
  }
  cout << sum << endl;
  vector<pair<int, int>> V;
  for (; !A.empty();) {
    if (V.empty()) {
      V.push_back(make_pair(A.top().first, A.top().second));
      A.pop();
    } else {
      if (A.top().first > V[k].first &&
          A.top().first + A.top().second < V[k].second + V[k].first) {
        V[k].second += A.top().second;
        A.pop();
      } else {
        k++;
        V.push_back(make_pair(A.top().first, A.top().second));
        A.pop();
      }
    }
  }
  if (!V.empty()) {
    cout << k + 1;
    i = 0;
    for (int j = k; j >= 0; j--) {
      cout << " " << V[j].second;
    }
    cout << endl;
  } else
    cout << k << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
// #include<cmath>
using namespace std;

int main(void) {
  int i = 0, sum = 0, k = 0, a, b;
  string s;
  stack<int> S;
  stack<pair<int, int>> A;
  cin >> s;
  while (i != s.size()) {
    switch (s[i]) {
    case '\\\\':
      S.push(i);
      break;
    case '_':
      i++;
      continue;
    case '/':
      if (!S.empty()) {
        sum += i - S.top();
        A.push(make_pair(S.top(), i - S.top()));
        S.pop();
      }
    }
    i++;
  }
  cout << sum << endl;
  vector<pair<int, int>> V;
  for (; !A.empty();) {
    if (V.empty()) {
      V.push_back(make_pair(A.top().first, A.top().second));
      A.pop();
    } else {
      if (A.top().first > V[k].first &&
          A.top().first + A.top().second < V[k].second + V[k].first) {
        V[k].second += A.top().second;
        A.pop();
      } else {
        k++;
        V.push_back(make_pair(A.top().first, A.top().second));
        A.pop();
      }
    }
  }
  cout << k + 1;
  i = 0;
  for (int j = k; j >= 0; j--) {
    cout << " " << V[j].second;
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <stack>
using namespace std;

int main() {
  int total_area = 0;

  stack<int> s1;
  stack<pair<int, int>> s2;

  char c;
  int i = 0;
  int ip, area;
  for (scanf("%c", &c); c != '\\n'; scanf("%c", &c), ++i) {
    switch (c) {
    case '\\\\':
      s1.push(i);
      break;
    case '_':
      break;
    case '/':
      if (s1.empty())
        break;
      ip = s1.top();
      s1.pop();
      area = i - ip;
      total_area += area;
      while (s2.empty() == false && s2.top().first > ip) {
        area += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(ip, area));
      break;
    }
  }

  int s = s2.size();
  int a[s];
  for (int i = s - 1; i >= 0; --i) {
    a[i] = s2.top().second;
    s2.pop();
  }

  printf("%d\\n", total_area);
  printf("%d", s);
  for (int i = 0; i < s; ++i)
    printf(" %d", a[i]);
  printf("\\n");

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <stack>
using namespace std;

int main() {
  int total_area = 0;

  stack<int> s1;
  stack<pair<int, int>> s2;

  char c;
  int i = 0;
  int ip, area;
  for (scanf("%c", &c); c != '\\n'; scanf("%c", &c), ++i) {
    switch (c) {
    case '\\\\':
      s1.push(i);
      break;
    case '_':
      break;
    case '/':
      ip = s1.top();
      s1.pop();
      area = i - ip;
      total_area += area;
      while (s2.empty() == false && s2.top().first > ip) {
        area += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(ip, area));
      break;
    }
  }

  int s = s2.size();
  int a[s];
  for (int i = s - 1; i >= 0; --i) {
    a[i] = s2.top().second;
    s2.pop();
  }

  printf("%d\\n", total_area);
  printf("%d", s);
  for (int i = 0; i < s; ++i)
    printf(" %d", a[i]);
  printf("\\n");

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  stack<int> p1, p2, s3;
  int i = 1, tmp = 0, sum = 0, tmps, cnt = 0;
  for (; i < s.length() + 1; i++) {
    if (s[i - 1] == '\\\\')
      p1.push(i);
    else if (s[i - 1] == '/' && !p1.empty()) {
      tmp = p1.top();
      p1.pop();
      p2.push(i - tmp);
      s3.push(tmp);
    }
  }
  while (!p1.empty())
    p1.pop();
  while (!p2.empty()) {
    tmp = s3.top();
    tmps = p2.top();
    s3.pop();
    p2.pop();
    if (!p2.empty() && tmp <= s3.top()) {
      tmps += p2.top();
      p2.pop();
      p2.push(tmps);
      s3.pop();
      s3.push(tmp);
    } else {
      p1.push(tmps);
      sum += tmps;
      cnt++;
    }
  }
  cout << sum << endl;
  cout << cnt;
  while (!p1.empty()) {
    cout << " ";
    tmp = p1.top();
    p1.pop();
    cout << tmp;
    if (p1.empty())
      break;
  }
  cout << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  cin >> s;
  stack<int> p1, p2, s3;
  int i = 1, tmp, sum, tmps, cnt = 0;
  for (; i < s.length() + 1; i++) {
    if (s[i - 1] == '\\\\')
      p1.push(i);
    else if (s[i - 1] == '/' && !p1.empty()) {
      tmp = p1.top();
      p1.pop();
      p2.push(i - tmp);
      s3.push(tmp);
    }
  }
  while (!p1.empty())
    p1.pop();
  while (!p2.empty()) {
    tmp = s3.top();
    tmps = p2.top();
    s3.pop();
    p2.pop();
    if (!p2.empty() && tmp <= s3.top()) {
      tmps += p2.top();
      p2.pop();
      p2.push(tmps);
      s3.pop();
      s3.push(tmp);
    } else {
      p1.push(tmps);
      sum += tmps;
      cnt++;
    }
  }
  cout << sum << endl;
  cout << cnt << " ";
  while (1) {
    tmp = p1.top();
    p1.pop();
    if (p1.empty())
      break;
    cout << tmp << " ";
  }
  cout << tmp << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<char> sc;
  int lim, m = 0, ds = 0, i = 0, k = 0, SS = 0;
  int s[10000];
  int rs[10000];
  char c;
  while (cin >> c) {
    sc.push(c);
    if (m == 0) {
      if (c == '\\\\')
        m++;
    } else {
      if (c == '/')
        m--;
      else if (c == '\\\\')
        m++;
    }
    ds = ds + m;
    if ((ds != 0) && (m == 0)) {
      s[i++] = ds;
      ds = 0;
      lim = sc.size();
      for (int j = 0; j < lim; j++)
        sc.pop();
    }
  }
  m = 0;
  ds = 0;
  lim = sc.size();
  for (int j = 0; j < lim; j++) {
    c = sc.top();
    sc.pop();
    if (m == 0) {
      if (c == '/')
        m++;
    } else {
      if (c == '\\\\')
        m--;
      else if (c == '/')
        m++;
    }
    ds = ds + m;
    if ((ds != 0) && (m == 0)) {
      rs[k++] = ds;
      ds = 0;
    }
  }
  for (int j = 0; j < i; j++)
    SS = SS + s[j];
  for (int j = 0; j < k; j++)
    SS = SS + rs[j];
  cout << SS << endl;
  cout << i + k;
  for (int j = 0; j < i; j++)
    cout << ' ' << s[j];
  for (int j = k - 1; j >= 0; j--)
    cout << ' ' << rs[j];
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<char> sc;
  int lim, m = 0, ds = 0, i = 0, k = 0, SS = 0;
  int s[1000];
  int rs[1000];
  char c;
  while (cin >> c) {
    sc.push(c);
    if (m == 0) {
      if (c == '\\\\')
        m++;
    } else {
      if (c == '/')
        m--;
      else if (c == '\\\\')
        m++;
    }
    ds = ds + m;
    if ((ds != 0) && (m == 0)) {
      s[i++] = ds;
      ds = 0;
      lim = sc.size();
      for (int j = 0; j < lim; j++)
        sc.pop();
    }
  }
  m = 0;
  ds = 0;
  lim = sc.size();
  for (int j = 0; j < lim; j++) {
    c = sc.top();
    sc.pop();
    if (m == 0) {
      if (c == '/')
        m++;
    } else {
      if (c == '\\\\')
        m--;
      else if (c == '/')
        m++;
    }
    ds = ds + m;
    if ((ds != 0) && (m == 0)) {
      rs[k++] = ds;
      ds = 0;
    }
  }
  for (int j = 0; j < i; j++)
    SS = SS + s[j];
  for (int j = 0; j < k; j++)
    SS = SS + rs[j];
  cout << SS << endl;
  cout << i + k;
  for (int j = 0; j < i; j++)
    cout << ' ' << s[j];
  for (int j = k - 1; j >= 0; j--)
    cout << ' ' << rs[j];
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

void Output(const std::vector<std::pair<int, int>> &List) {
  for (std::vector<std::pair<int, int>>::const_iterator It = List.begin();
       It != List.end(); ++It) {
    std::cout << " " << It->second;
  }
  std::cout << std::endl;
}

int main() {
  std::string l;
  std::cin >> l;

  std::vector<int> S1;
  std::vector<std::pair<int, int>> S2;
  int sum = 0;
  for (int i = 0; i < l.size(); ++i) {
    if (l[i] == '\\\\') {
      S1.push_back(i);
    } else if (l[i] == '/' && S1.empty() == false) {
      int j = S1.back();
      S1.pop_back();
      int a = i - j;
      sum += a;

      while (S2.empty() == false && S2.back().first > j) {
        a += S2.back().second;
        S2.pop_back();
      }
      S2.push_back(std::pair<int, int>(j, a));
    }
  }
  std::cout << sum << std::endl;
  std::cout << S2.size();
  Output(S2);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

void Output(const std::vector<std::pair<int, int>> &List) {
  std::vector<std::pair<int, int>>::const_iterator It = List.begin();
  std::cout << It->second;
  ++It;
  for (; It != List.end(); ++It) {
    std::cout << " " << It->second;
  }
  std::cout << std::endl;
}

int main() {
  std::string l;
  std::cin >> l;

  std::vector<int> S1;
  std::vector<std::pair<int, int>> S2;
  int sum = 0;
  for (int i = 0; i < l.size(); ++i) {
    if (l[i] == '\\\\') {
      S1.push_back(i);
    } else if (l[i] == '/' && S1.empty() == false) {
      int j = S1.back();
      S1.pop_back();
      int a = i - j;
      sum += a;

      while (S2.empty() == false && S2.back().first > j) {
        a += S2.back().second;
        S2.pop_back();
      }
      S2.push_back(std::pair<int, int>(j, a));
    }
  }
  std::cout << sum << std::endl;
  std::cout << S2.size() << " ";
  Output(S2);
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int main() {
  stack<int> s1;
  stack<pair<int, int>> s2;
  char c;
  int d;
  int sum = 0;
  for (int i = 0; cin >> c; i++) {
    if (c == '\\\\') {
      s1.push(i);
    } else if (c == '/' && s1.size() > 0) {
      int j = s1.top();
      d = i - j;
      sum += d;
      s1.pop();
      while (s2.size() > 0 && s2.top().first > j) {
        d += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j, d));
    }
  }
  int n = s2.size();
  vector<int> pond(n);
  for (int i = 0; i < n; i++) {
    pond[n - i - 1] = s2.top().second;
    s2.pop();
  }
  cout << sum << endl;
  cout << n;
  for (int i = 0; i < n; i++) {
    cout << ' ' << pond[i];
  }
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int main() {
  stack<int> s1;
  stack<pair<int, int>> s2;
  char c;
  int d;
  int sum = 0;
  for (int i = 0; cin >> c; i++) {
    if (c == '\\\\') {
      s1.push(i);
    } else if (c == '/') {
      int j = s1.top();
      d = i - j;
      sum += d;
      s1.pop();
      while (s2.size() > 0 && s2.top().first > j) {
        d += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j, d));
    }
  }
  int n = s2.size();
  vector<int> pond(n);
  for (int i = 0; i < n; i++) {
    pond[n - i - 1] = s2.top().second;
  }
  cout << sum << endl;
  cout << n;
  for (int i = 0; i < n; i++) {
    cout << ' ' << pond[i];
  }
  cout << endl;

  return 0;
}