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

#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  string str;
  int area = 0;
  char c;
  getline(cin, str);
  stack<int> stk;
  stack<pair<int, int>> stk2;
  stack<int> stk3;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '\\\\') {
      stk.push(i);

    } else if (str[i] == '/') {
      if (stk.empty())
        continue;

      int temp = i - stk.top();
      area += temp;
      pair<int, int> p = make_pair(stk.top(), temp);
      if (stk2.empty()) {
        stk2.push(p);
      } else {
        for (int l = i; l > p.first; l--) {
          if (stk2.empty())
            break;
          if (stk2.top().first == l) {
            p.second += stk2.top().second;
            stk2.pop();
          }
        }
        stk2.push(p);
      }
      stk.pop();
    }
  }

  cout << area << endl;
  int num = stk2.size();
  if (num != 0) {
    cout << num << " ";
    for (int i = 0; i < num; i++) {
      pair<int, int> P = stk2.top();
      stk3.push(P.second);
      stk2.pop();
    }
    for (int i = 0; i < num; i++) {

      cout << stk3.top();
      if (i != num - 1) {
        cout << " ";
      }
      stk3.pop();
    }
  } else {
    cout << num;
  }

  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  string str;
  int area = 0;
  char c;
  getline(cin, str);
  stack<int> stk;
  stack<pair<int, int>> stk2;
  stack<int> stk3;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '\\\\') {
      stk.push(i);

    } else if (str[i] == '/') {
      if (stk.empty())
        continue;

      int temp = i - stk.top();
      area += temp;
      pair<int, int> p = make_pair(stk.top(), temp);
      if (stk2.empty()) {
        stk2.push(p);
      } else {
        for (int l = i; l > p.first; l--) {
          if (stk2.top().first == l) {
            p.second += stk2.top().second;
            stk2.pop();
          }
        }
        stk2.push(p);
      }
      stk.pop();
    }
  }

  cout << area << endl;
  int num = stk2.size();
  cout << num << " ";
  for (int i = 0; i < num; i++) {
    pair<int, int> P = stk2.top();
    stk3.push(P.second);
    stk2.pop();
  }
  for (int i = 0; i < num; i++) {
    cout << stk3.top();
    if (i != num - 1) {
      cout << " ";
    }
    stk3.pop();
  }
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char *argv[]) {
  string buf;
  cin >> buf;

  int x = 0;
  int y = 0;
  stack<int> st;
  priority_queue<pii, vector<pii>, greater<pii>> q;
  for (size_t i = 0; i < buf.size(); i++) {
    char c = buf[i];
    x++;
    switch (c) {
    case '/':
      y++;
      if (!st.empty()) {
        q.push(pii(st.top(), x));
        st.pop();
      }
      break;
    case '\\\\':
      y--;
      st.push(x);
      break;
    }
  }
  vector<int> ret;
  int total = 0;
  while (!q.empty()) {
    pii p1 = q.top();
    q.pop();
    int s = p1.second - p1.first;
    while (!q.empty() && q.top().second < p1.second) {
      pii p2 = q.top();
      q.pop();
      s += p2.second - p2.first;
    }
    ret.push_back(s);
    total += s;
  }
  cout << total << endl;
  if (ret.size() == 0) {
    cout << ret.size() << endl;
    return 0;
  } else {
    cout << ret.size() << " ";
    for (size_t i = 0; i < ret.size() - 1; i++) {
      cout << ret[i] << " ";
    }
    cout << ret.back() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char *argv[]) {
  string buf;
  cin >> buf;

  int x = 0;
  int y = 0;
  stack<int> st;
  priority_queue<pii, vector<pii>, greater<pii>> q;
  for (size_t i = 0; i < buf.size(); i++) {
    char c = buf[i];
    x++;
    switch (c) {
    case '/':
      y++;
      if (!st.empty()) {
        q.push(pii(st.top(), x));
        st.pop();
      }
      break;
    case '\\\\':
      y--;
      st.push(x);
      break;
    }
  }
  vector<int> ret;
  int total = 0;
  while (!q.empty()) {
    pii p1 = q.top();
    q.pop();
    int s = p1.second - p1.first;
    while (!q.empty() && q.top().second < p1.second) {
      pii p2 = q.top();
      q.pop();
      s += p2.second - p2.first;
    }
    ret.push_back(s);
    total += s;
  }
  cout << total << endl;
  cout << ret.size() << " ";
  for (size_t i = 0; i < ret.size() - 1; i++) {
    cout << ret[i] << " ";
  }
  cout << ret.back() << endl;

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

#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {

  stack<int> sa;
  string m;
  int cnt = 0, result = 0, high = 0, tmp = 0, h[20000], i;
  vector<int> amo;

  cin >> m;
  for (i = m.size() - 1; i != -1; i--) {
    if (m[i] == '\\\\')
      tmp++;
    if (m[i] == '/')
      tmp--;
    if (tmp < 0) {
      for (int j = i + 1; j < m.size(); j++)
        h[j]++;
      high++;
      tmp = 0;
    }
    high = max(high, tmp);
    h[i] = high;
  }
  // for(i=0;i<m.size();i++) cout<<h[i]<<" ";

  for (i = 0; i < m.size(); i++) {
    //    if(i>0) if(h[i]-h[i-1]==1) sa.pop();
    if (m[i] == '\\\\') {
      sa.push(i);
    } else if (m[i] == '/' && !sa.empty()) {
      cnt += i - sa.top();
      sa.pop();
      if (sa.empty()) {
        amo.push_back(cnt);
        result += cnt;
        cnt = 0;
      }
    }
    if (i < m.size() - 1)
      if (h[i + 1] - h[i] != 0)
        sa.pop();
  }
  if (cnt != 0) {
    amo.push_back(cnt);
    result += cnt;
  }
  if (amo.empty())
    cout << "0" << endl << "0" << endl;
  else {
    cout << result << endl << amo.size() << " ";
    for (i = 0; i < amo.size() - 1; i++)
      cout << amo[i] << " ";
    cout << amo[amo.size() - 1] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {

  stack<int> sa;
  string m;
  int cnt = 0, result = 0, high = 0, tmp = 0, h[20000], i;
  vector<int> amo;

  cin >> m;
  for (i = m.size() - 1; i != -1; i--) {
    if (m[i] == '\\\\')
      tmp++;
    if (m[i] == '/')
      tmp--;
    if (tmp < 0) {
      for (int j = i + 1; j < m.size(); j++)
        h[j]++;
      high++;
      tmp = 0;
    }
    high = max(high, tmp);
    h[i] = high;
  }
  // for(i=0;i<m.size();i++) cout<<h[i]<<" ";

  for (i = 0; i < m.size(); i++) {
    //    if(i>0) if(h[i]-h[i-1]==1) sa.pop();
    if (m[i] == '\\\\') {
      sa.push(i);
    } else if (m[i] == '/' && !sa.empty()) {
      cnt += i - sa.top();
      sa.pop();
      if (sa.empty()) {
        amo.push_back(cnt);
        result += cnt;
        cnt = 0;
      }
    }
    if (i < m.size() - 1)
      if (h[i + 1] - h[i] != 0)
        sa.pop();
  }
  if (cnt != 0) {
    amo.push_back(cnt);
    result += cnt;
  }
  cout << result << endl << amo.size() << " ";
  for (i = 0; i < amo.size() - 1; i++)
    cout << amo[i] << " ";
  cout << amo[amo.size() - 1] << endl;

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

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

int main() {
  string area;
  cin >> area;

  stack<int> slope;
  deque<int> L;
  int A = 0;
  vector<int> down;
  int j = 0;
  for (int i = 0; i < area.size(); i++) {
    if (area[i] == '\\\\') {
      slope.push(i);
      down.push_back(i);
      j++;
    } else if (area[i] == '/') {
      if (slope.empty()) {
        down.clear();
        j = 0;
        continue;
      }

      L.push_back(i - slope.top());
      A += i - slope.top();

      while (j > 0) {
        j--;

        if (slope.top() < down[j]) {
          down.erase(down.begin() + j);
          int plus = L.back();
          L.pop_back();
          plus += L.back();
          L.pop_back();
          L.push_back(plus);
        } else if (j == 0) {
          break;
        }
      }

      j = down.size();

      slope.pop();
    }
  }

  cout << A << endl;
  if (!L.empty()) {
    cout << L.size() << " ";
  } else {
    cout << L.size() << endl;
  }
  while (!L.empty()) {
    if (L.size() == 1) {
      cout << L.front() << endl;
    } else {
      cout << L.front() << " ";
    }
    L.pop_front();
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main() {
  char area[20001];
  scanf("%s", area);
  int arealen = strlen(area);

  int start = 0, end = 0;
  int j = 0;
  vector<double> L;
  while (start < arealen) {
    int up = 0, down = 0;
    for (int i = start; i < arealen; i++) {
      if (area[i] == '\\\\') {
        if (!down && i != start) {
          start = i;
          up = 0, down = 1;
          continue;
        }
        down++;
      } else if (area[i] == '/') {
        up++;
      }

      if (up && up == down) {
        end = i;
        break;
      }

      if (i == arealen - 1 && up != down) {
        end = start;
      }
    }

    if (up != down) {
      start++;
      continue;
    }

    int height = 0;
    for (int i = start; i <= end; i++) {
      if (area[i] == '\\\\') {
        if (i == start) {
          L.push_back(0);
        }
        L[j] += height + 0.5;
        height++;
      } else if (area[i] == '/') {
        L[j] += height - 0.5;
        height--;
      } else if (area[i] == '_') {
        L[j] += height;
      }
    }

    if (start != end) {
      j++;
    }
    start = end + 1;
  }

  int A = 0;
  for (int i = 0; i < (int)L.size(); i++) {
    A += L[i];
  }

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

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

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  stack<int> s1;
  stack<pair<int, int>> s2;
  string str;
  cin >> str;
  int sum = 0;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == '\\\\')
      s1.push(i);
    else if (str[i] == '/' && 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;
  while (s2.size() > 0) {
    ans.push_back(s2.top().second);
    s2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (vector<int>::iterator it = ans.begin(); it != ans.end(); it++)
    cout << " " << *it;
  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 <utility>
#include <vector>
using namespace std;
int main() {
  stack<int> s1;
  stack<pair<int, int>> s2;
  string str;
  cin >> str;
  int sum = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '\\\\')
      s1.push(i);
    else if (str[i] == '/' && 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;
  while (s2.size() > 0)
    ans.push_back(s2.top().second);
  s2.pop();
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (vector<int>::iterator it = ans.begin(); it != ans.end(); it++)
    cout << " " << *it;
  cout << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;
  stack<int> st1;
  stack<pair<int, int>> st2;
  int ans = 0;

  for (int i = 0; i < S.size(); ++i) {
    if (S.at(i) == '\\\\') {
      st1.push(i);
    } else if (S.at(i) == '/' && !st1.empty()) {
      int j = st1.top();
      st1.pop();
      int num = i - j;
      ans += num;
      while (!st2.empty() && st2.top().first > j) {
        num += st2.top().second;
        st2.pop();
      }
      st2.push(make_pair(j, num));
    }
  }
  vector<int> V;
  while (!st2.empty()) {
    V.push_back(st2.top().second);
    st2.pop();
  }
  cout << ans << endl;
  cout << V.size();
  for (int i = V.size() - 1; i >= 0; --i) {
    cout << ' ' << V.at(i);
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  int A[10010], ans = 0, n = 0;

  for (int i = 0; i < s.size();) {
    if (s[i] == '\\\\') {
      int dl = 0, hl = 0, ul = 0;
      for (int j = i; s[j] == '\\\\'; ++j) {
        ++dl;
      }
      if (s[i + dl] == '_') {
        for (int j = i + dl; s[j] == '_'; ++j) {
          ++hl;
        }
      } else if (s[i + dl] == '/') {
        for (int j = i + dl; s[j] == '/'; ++j) {
          ++ul;
        }
      }
      if (s[i + dl + hl] == '/') {
        for (int j = i + dl + hl; s[j] == '/'; ++j) {
          ++ul;
        }
      }
      if (dl > ul) {
        A[n] = ul * ul + hl * ul;
        ans += A[n];
      } else {
        A[n] = dl * dl + hl * dl;
        ans += A[n];
      }
      ++n;
      i += dl + hl + ul;
    }
  }

  cout << ans << endl << n;
  for (int i = 0; i < n; ++i) {
    cout << ' ' << A[i];
  }
  cout << endl;

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  stack<int> ST;
  stack<pair<int, int>> MIZU;
  char YAMA[2000001];
  int sum = 0;

  cin >> YAMA;
  int len = strlen(YAMA);
  for (int i = 0; i < len; i++) {
    if (YAMA[i] == '\\\\')
      ST.push(i);
    else if (YAMA[i] == '/' && ST.size() > 0) {
      int ker = ST.top();
      ST.pop();
      sum += i - ker;
      int mymizu = i - ker;
      while (MIZU.size() > 0 && ker < MIZU.top().first) {
        mymizu += MIZU.top().second;
        MIZU.pop();
      }
      MIZU.push(make_pair(ker, mymizu));
    }
  }

  stack<int> ss;

  while (MIZU.size() > 0) {
    ss.push(MIZU.top().second);
    MIZU.pop();
  }
  int coun = ss.size();
  printf("%d\\n", sum);
  printf("%d", coun);
  while (ss.size() > 0) {
    printf(" %d", ss.top());
    ss.pop();
  }
  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  stack<int> ST;
  stack<pair<int, int>> MIZU;
  char YAMA[102];
  int sum = 0;

  scanf("%s", YAMA);

  int len = strlen(YAMA);

  for (int i = 0; i < len; i++) {
    if (YAMA[i] == '\\\\') {
      ST.push(i);
    } else if (YAMA[i] == '/' && !ST.empty()) {
      int mymizu = i - ST.top();
      while (!MIZU.empty() && ST.top() < MIZU.top().first) {
        mymizu += MIZU.top().second;
        MIZU.pop();
      }
      sum += i - ST.top();
      MIZU.push(make_pair(ST.top(), mymizu));
      ST.pop();
    }
  }

  vector<int> V;
  int n = MIZU.size();

  while (!MIZU.empty()) {
    V.push_back(MIZU.top().second);
    MIZU.pop();
  }
  reverse(V.begin(), V.end());
  printf("%d\\n%d", sum, n);
  for (int i = 0; i < n; i++) {
    printf(" %d", V[i]);
  }
  printf("\\n");
  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: -11

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.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: Runtime Error

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

int main() {
  using namespace std;
  stack<int> S1;
  stack<pair<int, int>> S2;
  vector<int> V1;
  char ch;
  int total = 0;
  for (int i = 0; cin >> ch; i++) {
    switch (ch) {
    case '\\\\':
      S1.push(i);
      break;
    case '/':
      if (!S1.empty()) {
        int start = S1.top();
        S1.pop();
        total += i - start;
        int t_area = i - start;
        while (!S2.empty() && (S2.top().first > start)) {
          t_area += S2.top().second;
          S2.pop();
        }
        S2.push(make_pair(start, t_area));
      }
      break;
    default:
      break;
    }
  }

  while (!S2.empty()) {
    V1.push_back(S2.top().second);
    S2.pop();
  }
  reverse(V1.begin(), V1.end());
  cout << total << endl;
  cout << V1.size();
  for (int i = 0; i < V1.size(); i++) {
    cout << ' ' << V1[i];
  }
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  using namespace std;
  stack<int> S1;
  stack<pair<int, int>> S2;
  vector<int> V1;
  char ch;
  int total = 0;
  for (int i = 0; cin >> ch; i++) {
    switch (ch) {
    case '\\\\':
      S1.push(i);
      break;
    case '/':
      if (!S1.empty()) {
        int start = S1.top();
        S1.pop();
        total += i - start;
        int t_area = i - start;
        while (!S2.empty() && (S2.top().first > start)) {
          t_area += S2.top().second;
          S2.pop();
        }
        S2.push(make_pair(start, t_area));
      }
      break;
    default:
      break;
    }
  }

  while (!S2.empty()) {
    V1.push_back(S2.top().second);
    S2.pop();
  }
  reverse(V1.begin(), V1.end());
  cout << total << endl;
  cout << V1.size() << ' ';
  for (int i = 0; i < V1.size() - 1; i++) {
    cout << V1[i] << ' ';
  }
  cout << V1[V1.size() - 1] << endl;
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

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

int out(vector<int> &A, int n) {
  int i;
  for (i = 0; i <= n - 2; i++) {
    cout << A[i] << " ";
  }
  cout << A[n - 1] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  vector<char> C_list;
  char c;
  while (cin >> c) {
    C_list.push_back(c);
  }

  vector<int> A_list;
  int n = C_list.size();
  int i = 0;
  while (i < n) {
    char s = C_list[i];
    if (s == '\\\\') {
      int j = i;
      int A2 = 1;
      int height = -1;
      while (height < 0) {
        j++;
        if (j == n) {
          break;
        }
        char s2 = C_list[j];
        if (s2 == '/') {
          A2 += (-2 * height - 1);
          height += 1;
        } else if (s2 == '\\\\') {
          A2 += (-2 * height + 1);
          height -= 1;
        } else {
          A2 += (-2 * height);
        }
      }
      if (height == 0) {
        A_list.push_back(A2 / 2);
        i = j;
      }
    }
    i++;
  }
  int A = accumulate(A_list.begin(), A_list.end(), 0);
  cout << A << endl;
  if (A == 0) {
    cout << 0 << endl;
  } else {
    int m = A_list.size();
    cout << m << " ";
    out(A_list, m);
  }
  return 0;
}

Error: 0

Fixed submission:

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

int out(vector<int> &A, int n) {
  int i;
  for (i = 0; i <= n - 2; i++) {
    cout << A[i] << " ";
  }
  cout << A[n - 1] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  vector<char> C_list;
  char c;
  while (cin >> c) {
    C_list.push_back(c);
  }

  vector<int> A_list;
  int n = C_list.size();
  int i = 0;
  while (i < n) {
    char s = C_list[i];
    if (s == '\\\\') {
      int j = i;
      int A2 = 1;
      int height = -1;
      while (height < 0) {
        j++;
        if (j == n) {
          break;
        }
        char s2 = C_list[j];
        if (s2 == '/') {
          A2 += (-2 * height - 1);
          height += 1;
        } else if (s2 == '\\\\') {
          A2 += (-2 * height + 1);
          height -= 1;
        } else {
          A2 += (-2 * height);
        }
      }
      if (height == 0) {
        A_list.push_back(A2 / 2);
        i = j;
      }
    }
    i++;
  }
  int A = accumulate(A_list.begin(), A_list.end(), 0);
  cout << A << endl;
  int m = A_list.size();
  cout << m << " ";
  out(A_list, m);

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

#include <iostream>
using namespace std;

bool linearSearch(int A[], int key, int size) {
  int i = 0;
  A[size] = key;
  while (A[i] != key)
    i++;
  return i != size;
}

int main() {
  int size, query, queryNum, count = 0;

  cin >> size;
  int *A = new int[size + 1];
  for (int i = 0; i < size; i++)
    scanf("%d", &A[i]);

  cin >> queryNum;
  for (int i = 0; i < queryNum; i++) {
    scanf("%d", &query);
    if (linearSearch(A, query, size))
      count++;
  }

  cout << count << endl;

  delete[] A;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

bool linearSearch(int A[], int key, int size) {
  int i = 0;
  A[size] = key;
  while (A[i] != key)
    i++;
  return i != size;
}

int main() {
  int size, query, queryNum, count = 0;

  cin >> size;
  int *A = new int[size];
  for (int i = 0; i < size; i++)
    scanf("%d", &A[i]);

  cin >> queryNum;
  for (int i = 0; i < queryNum; i++) {
    scanf("%d", &query);
    if (linearSearch(A, query, size))
      count++;
  }

  cout << count << endl;

  delete[] A;
}