alexjercan/bugnet huggingface dataset:
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define UP '/'
#define DOWN '\\\\'
#define FLAT '_'
#define END 20001

int calc_area(int i, int j, const string *input) {
  int area = 0, d = 0;
  while (i < j) {
    if ((*input)[i] == UP)
      area += d--;
    else if ((*input)[i] == DOWN)
      area += d++;
    else
      area += d;
    i++;
  }
  return area;
}

int main(void) {
  vector<int> areas, heights;
  string input;
  cin >> input;

  int h = 0;
  heights.push_back(0);
  for (auto x : input) {
    if (x == DOWN)
      h--;
    else if (x == UP)
      h++;
    heights.push_back(h);
  }
  heights.push_back(END);

  int i = 0, k = 0, total = 0;
  while (heights[i] != END) {
    int j = i + 1;
    while (heights[j] != END && heights[j] < heights[i])
      j++;
    if (heights[i] == heights[j]) {
      int area = calc_area(i, j, &input);
      if (area > 0) {
        total += area;
        areas.push_back(area);
        k++;
      }
      i = j;
    } else
      i++;
  }

  printf("%d\\n%d", total, k);
  if (k > 0)
    for (int i = 0; i < k; i++)
      printf(" %d", areas[i]);
  puts("");

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define UP '/'
#define DOWN '\\\\'
#define FLAT '_'
#define END 20001

int calc_area(int i, int j, const string *input) {
  int area = 0, d = 0;
  while (i < j) {
    if ((*input)[i] == UP)
      area += d--;
    else if ((*input)[i] == DOWN)
      area += d++;
    else
      area += d;
    i++;
  }
  return area;
}

int main(void) {
  vector<int> areas, heights;
  string input;
  cin >> input;

  int h = 0;
  heights.push_back(0);
  for (auto x : input) {
    if (x == DOWN)
      h--;
    else if (x == UP)
      h++;
    heights.push_back(h);
  }
  heights.push_back(END);

  int i = 0, k = 0, total = 0;
  while (heights[i] != END) {
    int j = i + 1;
    while (heights[j] != END && heights[j] < heights[i])
      j++;
    if (heights[i] == heights[j]) {
      int area = calc_area(i, j, &input);
      if (area > 0) {
        total += area;
        areas.push_back(area);
        k++;
      }
      i = j;
    } else
      i++;
  }

  printf("%d\\n%d ", total, k);
  for (int i = 0; i < k - 1; i++)
    printf("%d ", areas[i]);
  printf("%d\\n", areas[k - 1]);

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

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> p;

int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, 1, -1};

string s;

int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  stack<int> st;
  stack<p> st2;
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\\\\') {
      st.push(i);
    } else if (s[i] == '/' & st.size() > 0) {
      int j = st.top();
      st.pop();
      sum += i - j;
      int a = i - j;
      while (st2.size() > 0 && st2.top().first > j) {
        a += st2.top().second;
        st2.pop();
      }
      st2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (st2.size()) {
    ans.pb(st2.top().second);
    st2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  REP(i, ans.size()) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> p;

int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, 1, -1};

char ch;

int main() {
  ios::sync_with_stdio(false);
  stack<int> st;
  stack<p> st2;
  int sum = 0;
  for (int i = 0; cin >> ch; i++) {
    if (ch == '\\\\') {
      st.push(i);
    } else if (ch == '/' & st.size() > 0) {
      int j = st.top();
      st.pop();
      sum += i - j;
      int a = i - j;
      while (st2.size() > 0 && st2.top().first > j) {
        a += st2.top().second;
        st2.pop();
      }
      st2.push(p(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (st2.size()) {
    ans.pb(st2.top().second);
    st2.top();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  REP(i, ans.size()) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;

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

#include "bits/stdc++.h"
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; ++i) {
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }
  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); ++i) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include "bits/stdc++.h"
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; ++i) {
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }
  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.top();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); ++i) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; ++i) {
    if (ch == '0')
      break;
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;

  printf("Hello!\\n");
  for (int i = 0;; ++i) {
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

string input;
queue<char> q, q2;
vector<int> pool;

//?°´???????????????????????°???
int f() {

  while (true) {
    if (q.empty())
      return 0;
    if (q.front() == '\\\\')
      break;
    q.pop();
  }

  int h = 0, oldh = 0, res = 0;
  while (!q2.empty())
    q2.pop();
  while (true) {
    char c = q.front();
    h += (c == '\\\\');
    h -= (c == '/');

    res += h + oldh;

    if (h == 0) {
      break;
    }

    q2.push(c);
    q.pop();
    if (q.empty()) {
      q2.pop();
      q = q2;
      return f();
    }

    oldh = h;
  }
  return res;
}

int main() {
  cin >> input;
  for (int i = 0; i < input.size(); i++)
    q.push(input[i]);
  int n = f() / 2;
  while (n != 0) {
    pool.push_back(n);
    n = f() / 2;
  }

  int total = 0;
  for (int i = 0; i < pool.size(); i++)
    total += pool[i];

  cout << total << endl;
  cout << pool.size();
  for (int i = 0; i < pool.size(); i++)
    cout << " " << pool[i];
  cout << endl;
}

Error: MLE

Fixed submission:

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

string input;
queue<char> q;
vector<int> pool;

//?°´???????????????????????°???
int f() {

  while (true) {
    if (q.empty())
      return 0;
    if (q.front() == '\\\\')
      break;
    q.pop();
  }

  queue<char> q2;
  int h = 0, oldh = 0, res = 0;
  while (true) {
    char c = q.front();
    h += (c == '\\\\');
    h -= (c == '/');

    res += h + oldh;

    if (h == 0) {
      break;
    }

    q2.push(c);
    q.pop();
    if (q.empty()) {
      q2.pop();
      q = q2;
      return f();
    }

    oldh = h;
  }
  return res;
}

int main() {
  cin >> input;
  for (int i = 0; i < input.size(); i++)
    q.push(input[i]);
  int n = f() / 2;
  while (n != 0) {
    pool.push_back(n);
    n = f() / 2;
  }

  int total = 0;
  for (int i = 0; i < pool.size(); i++)
    total += pool[i];

  cout << total << endl;
  cout << pool.size();
  for (int i = 0; i < pool.size(); i++)
    cout << " " << pool[i];
  cout << endl;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;

char s[20003];
stack<int> sta;
vector<P> ku;

int main() {

  scanf("%s", s);
  int res = 0;
  for (int i = 0; i < sizeof(s); i++) {
    if (s[i] == '\\\\') {
      sta.push(i);
    }
    if (s[i] == '/' && !sta.empty()) {
      int mama = sta.top();
      sta.pop();
      res += i - mama;
      ku.push_back(P(mama, i));
    }
  }

  vector<int> ma;

  for (vector<P>::iterator it = ku.begin(); it != ku.end(); it++) {
    int ress = it->second - it->first;
    bool flg = true;
    for (vector<P>::iterator gt = ku.begin(); gt != ku.end(); gt++) {
      if (it->first < gt->first && it->second > gt->second) {
        ress += gt->second - gt->first;
      }
      if (it->first > gt->first && it->second < gt->second)
        flg = false;
    }
    if (flg)
      ma.push_back(ress);
  }

  printf("%d\\n", res);
  printf("%d", ma.size());
  for (vector<int>::iterator it = ma.begin(); it != ma.end(); it++)
    printf(" %d", *it);
  printf("\\n");

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

int solve(vector<char> que) {
  int h = 0;
  int f[que.size()];
  f[0] = 1;
  for (int i = 1; i < que.size(); i++) {
    if (que[i] == '\\\\')
      f[i] = f[i - 1] + 1;
    else if (que[i] == '/' && que[i - 1] == '/')
      f[i] = f[i - 1] - 1;
    else if (que[i] == '/' && que[i - 1] == '\\\\')
      f[i] = f[i - 1];
    else if (que[i] == '_' && que[i - 1] == '/')
      f[i] = 2 * (f[i - 1] - 1);
    else if (que[i] == '_' && que[i - 1] == '\\\\')
      f[i] = 2 * f[i - 1];
  }

  int yu = 0;
  for (int i = 0; i < que.size(); i++)
    yu += f[i] / 2;

  return yu;
}

int main() {
  string s;
  vector<char> que;
  vector<int> ans;

  // cin >> s;
  scanf("%s", &s);

  int tmp = 0;
  int tmp2 = 0;
  for (int i = 0; i < s.size(); i++) {

    if (s[i] == '\\\\')
      tmp++;
    if (s[i] == '/')
      tmp--;
    if (tmp == 0) {
      for (int j = 0; j < tmp2 - i; j++)
        que.push_back(s.at(j));
      ans.push_back(solve(que));

      tmp2 = i;
    }
  }

  int go = 0;
  for (int i = 0; i < ans.size(); i++)
    go += ans[i];

  cout << go << endl;
  printf("%d ", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    if (i == ans.size() - 1)
      printf("%d\\n", ans[i]);
    else
      printf("%d ", ans[i]);
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stack>
#include <stdlib.h>
#include <string>
#define lens 10000

using namespace std;
stack<pair<int, int>> S2;
stack<int> S1;
int a[lens];
int main() {
  char c;
  int i = 0;
  int total = 0;
  while (cin >> c) {
    if (c == '\\\\') {
      S1.push(i);
      i++;
      int h = 0;
    } else if (c == '/') {
      if (S1.size() > 0) {
        int t = S1.top();
        S1.pop();
        int a = i - t;
        total += a;
        i++;
        while (S2.size() > 0 && S2.top().first > t) {
          int sum = S2.top().second;
          S2.pop();
          a = a + sum;
        }
        S2.push(make_pair(t, a));
      }
    } else if (c == '_') {
      if (S1.size() > 0)
        i++;
    } else if (c == '1') {
      break;
    }
  }
  cout << total << endl;
  cout << S2.size();
  int m = S2.size();
  for (int j = 0; j < m; j++) {
    a[j] = S2.top().second;
    S2.pop();
  }
  for (int j = m - 1; j >= 0; j--) {
    cout << ' ';
    cout << a[j];
  }
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stack>
#include <stdlib.h>
#include <string>

using namespace std;
stack<pair<int, int>> S2;
stack<int> S1;
int main() {
  char c;
  int i = 0;
  int total = 0;
  while (cin >> c) {
    if (c == '\\\\') {
      S1.push(i);
      i++;
    } else if (c == '/') {
      int t = S1.top();
      S1.pop();
      int a = i - t;
      total += a;
      i++;
      if (S2.size() > 0 && S2.top().first > t) {
        int sum = S2.top().second;
        S2.pop();
        sum += a;
        S2.push(make_pair(t, sum));
      } else
        S2.push(make_pair(t, a));
    } else if (c == '_') {
      if (S1.size() > 0)
        i++;
    }
  }
  cout << total << endl;
  cout << S2.size();
  for (int j = 0; j < S2.size(); j++) {
    cout << ' ';
    cout << S2.top().second;
    S2.pop();
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; ++i) {
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; ++i) {
    if (ch == '\\\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.top();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  stack<int> S1;
  stack<pair<int, int>> S2;
  stack<int> res;
  char c;
  int i = 0;
  int j = 0;
  int v, all = 0;
  while (cin >> c) {
    i++;
    switch (c) {
    case '\\\\':
      S1.push(i);
      break;
    case '/':
      if (S1.size() == 0)
        break;
      j = S1.top();
      S1.pop();
      v = i - j;
      all += v;
      while (S2.size() > 0 && S2.top().first > j) {
        v += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, v));
      break;
    default:
      break;
    }
  }
  cout << all << endl;
  cout << S2.size();
  while (S2.size() > 0) {
    res.push(S2.top().second);
    S2.pop();
  }
  while (res.size() > 0) {
    cout << " " << res.top();
    res.pop();
  }
  cout << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  stack<int> S1;
  stack<pair<int, int>> S2;
  stack<int> res;
  char c;
  int i = 0;
  int j = 0;
  int v, all = 0;
  while (cin >> c) {
    i++;
    switch (c) {
    case '\\\\':
      S1.push(i);
      break;
    case '/':
      if (S1.size() == 0)
        break;
      j = S1.top();
      S1.pop();
      v = i - j;
      all += v;
      while (S2.size() > 0 && S2.top().first > j) {
        v += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, v));
      break;
    default:
      break;
    }
  }
  cout << all << endl;
  cout << S2.size() << " ";
  while (S2.size() > 0) {
    res.push(S2.top().second);
    S2.pop();
  }
  while (res.size() > 1) {
    cout << res.top() << " ";
    res.pop();
  }
  cout << res.top() << endl;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

int main() {
  char s;
  int N;
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0;
  int ans[20000];
  for (int i = 0; cin >> s; i++) {
    if (s == '\\\\') {
      S1.push(i);
    } else if (s == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      int a = i - j;
      sum += a;
      while (S2.size() > 0 && j < S2.top().first) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(i, a));
      //	cout << S2.top().first <<"    " << S2.top().second << "    "
      //<<sum<< endl;
    } else if (s == '\\n') {
      break;
    }
  }

  N = S2.size();

  for (int i = 0; i < N; i++) {
    ans[i] = S2.top().second;
    S2.pop();
  }

  cout << sum << endl;
  cout << N;
  for (int i = N - 1; i >= 0; i--) {
    cout << ' ' << ans[i];
  }
  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

int main() {
  char s;
  int N;
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0;
  int ans[1000];
  for (int i = 0; cin >> s; i++) {
    if (s == '\\\\') {
      S1.push(i);
    } else if (s == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      int a = i - j;
      sum += a;
      while (S2.size() > 0 && j < S2.top().first) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(i, a));
      //	cout << S2.top().first <<"    " << S2.top().second << "    "
      //<<sum<< endl;
    } else if (s == '\\n') {
      break;
    }
  }

  N = S2.size();

  for (int i = 0; i < N; i++) {
    ans[i] = S2.top().second;
    S2.pop();
  }

  cout << sum << endl;
  cout << N;
  for (int i = N - 1; i >= 0; i--) {
    cout << ' ' << ans[i];
  }
  cout << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char slope;
  int i = 0;
  int sum = 0;
  while (cin >> slope) {
    if (slope == '\\\\') {
      S1.push(i);
    } else if (slope == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
    i++;
  }
  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  char slope;
  int i = 0;
  int sum = 0;
  while (scanf("%s", slope) != EOF) {
    if (slope == '\\\\') {
      S1.push(i);
    } else if (slope == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
    i++;
  }
  vector<int> ans;
  int t = 0;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;
  return 0;
}