Problem p00861 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define INF 0x7FFFFFFF
#define ll int

ll get_num();

string s;
vector<map<ll, ll>> a;
vector<ll> b;
vector<ll> c;

int t;

//[   -1
//]   -2

void pr(vector<ll> k) {
  cout << "x ";
  for (int i = 0; i < k.size(); i++) {
    cout << k[i] << " ";
  }
  cout << endl;
}

int main() {
  vector<ll> z;
  map<ll, ll> m;
  cin >> s;
  while (s != ".") {
    ll ans = 0;
    ll an = 0;
    a.assign(52, m);
    c.assign(52, 0);

    while (s != "." && ans == 0) {
      b.assign(0, 0);
      an++;
      int f = 0;
      int e = 0;
      t = 0;
      for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '[') {
          b.push_back(-64);
        } else if (s[i] == ']') {
          b.push_back(-65);
          f = 0;
        } else if (s[i] == '=') {
          b.push_back(-66);
          e++;
        } else if ('a' <= s[i] && s[i] <= 'z') {
          b.push_back(-1 - (s[i] - 'a'));
        } else if ('A' <= s[i] && s[i] <= 'Z') {
          b.push_back(-1 - (s[i] - 'A' + 26));
        } else if ('0' <= s[i] && s[i] <= '9') {
          if (f == 0) {
            b.push_back(s[i] - '0');
            f++;
          } else {
            b[b.size() - 1] *= 10;
            b[b.size() - 1] += s[i] - '0';
          }
        }
      }
      if (e == 0) {
        ll ra, rb;
        ra = -b[t] - 1;
        t++;
        t++;
        rb = get_num();
        t++;
        if (rb >= 0) {
          // a[ra].assign(rb,-1);
          c[ra] = rb;
        } else {
          ans = an;
        }
      } else {
        ll ra, rb, rc;
        ra = -b[t] - 1;
        t++;
        t++;
        rb = get_num();
        t++;
        t++;
        rc = get_num();
        t++;
        if (rb < (int)c[ra] && rc >= 0) {
          a[ra][rb] = rc + 1;
        } else {
          ans = an;
        }
      }
      cin >> s;
    }
    cout << ans << endl;
    while (s != ".") {
      cin >> s;
    }
    cin >> s;
  }
}

ll get_num() {
  if (b[t] >= 0) {
    t++;
    return b[t - 1];
  } else {
    ll ra, rb;
    ra = -b[t] - 1;
    t++;
    t++;
    rb = get_num();
    t++;
    if (rb < c[ra]) {
      return a[ra][rb] - 1;
    } else {
      return -1;
    }
  }
}


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


Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define INF 0x7FFFFFFF
#define ll long long

ll get_num();

string s;
vector<vector<ll>> a;
vector<ll> b;
int t;

//[   -1
//]   -2

void pr(vector<ll> k) {
  cout << "x ";
  for (int i = 0; i < k.size(); i++) {
    cout << k[i] << " ";
  }
  cout << endl;
}

int main() {
  vector<ll> z;
  cin >> s;
  while (s != ".") {
    ll ans = 0;
    ll an = 0;
    a.assign(52, z);
    while (s != "." && ans == 0) {
      b.assign(0, 0);
      an++;
      int f = 0;
      int e = 0;
      t = 0;
      for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '[') {
          b.push_back(-64);
        } else if (s[i] == ']') {
          b.push_back(-65);
          f = 0;
        } else if (s[i] == '=') {
          b.push_back(-66);
          e++;
        } else if ('a' <= s[i] && s[i] <= 'z') {
          b.push_back(-1 - (s[i] - 'a'));
        } else if ('A' <= s[i] && s[i] <= 'Z') {
          b.push_back(-1 - (s[i] - 'A' + 26));
        } else if ('0' <= s[i] && s[i] <= '9') {
          if (f == 0) {
            b.push_back(s[i] - '0');
            f++;
          } else {
            b[b.size() - 1] *= 10;
            b[b.size() - 1] += s[i] - '0';
          }
        }
      }
      if (e == 0) {
        ll ra, rb;
        ra = -b[t] - 1;
        t++;
        t++;
        rb = get_num();
        t++;
        if (rb >= 0) {
          a[ra].assign(rb, -1);
        } else {
          ans = an;
        }
      } else {
        ll ra, rb, rc;
        ra = -b[t] - 1;
        t++;
        t++;
        rb = get_num();
        t++;
        t++;
        rc = get_num();
        t++;
        if (rb < (int)a[ra].size() && rc >= 0) {
          a[ra][rb] = rc;
        } else {
          ans = an;
        }
      }
      cin >> s;
    }
    cout << ans << endl;
    while (s != ".") {
      cin >> s;
    }
    cin >> s;
  }
}

ll get_num() {
  if (b[t] >= 0) {
    t++;
    return b[t - 1];
  } else {
    ll ra, rb;
    ra = -b[t] - 1;
    t++;
    t++;
    rb = get_num();
    t++;
    if (rb < a[ra].size()) {
      return a[ra][rb];
    } else {
      return -1;
    }
  }
}