Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007
#define irep(i, n) for (int i = 0; i < n; i++)
#define irep2(i, a, n) for (int i = a; i < n; i++)
#define lrep(i, n) for (long long i = 0; i < n; i++)
#define lrep2(i, a, n) for (long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int>> v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll>> v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string>> v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool>> v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

string input;
ll ans = 0;

void solve(string s) {
  int i = 0;
  string num = "";
  ll sum = 0;
  s += "+";

  while (i < s.size()) {
    if (s[i] != '+') {
      num += s[i];
    } else {
      if (num == "9999999999") {
        sum += 9999999999;
      } else {
        sum += stoi(num);
      }
      num = "";
    }
    i++;
  }
  ans += sum;
}

void make_string(int bit) {
  int i = 0;
  string t("");
  irep(j, input.size()) {
    t += input[j];
    if (bit & (0x1 << j)) {
      t += "+";
    }
  }
  // t += input.back();
  // cout << t << endl;
  solve(t);
}

void make_bit(int n, int i, int bit) {
  if (n == i) {
    // cout << bit << endl;
    make_string(bit);
    return;
  }
  make_bit(n, i + 1, bit);
  make_bit(n, i + 1, bit | (0x1 << i));
}

int main() {
  cin >> input;

  make_bit(input.size() - 1, 0, 0);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007
#define irep(i, n) for (int i = 0; i < n; i++)
#define irep2(i, a, n) for (int i = a; i < n; i++)
#define lrep(i, n) for (long long i = 0; i < n; i++)
#define lrep2(i, a, n) for (long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int>> v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll>> v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string>> v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool>> v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

string input;
ll ans = 0;

void solve(string s) {
  int i = 0;
  string num = "";
  ll sum = 0;
  s += "+";

  while (i < s.size()) {
    if (s[i] != '+') {
      num += s[i];
    } else {
      if (num.size() > 9) {
        sum += (num[0] - '0') * 1e9;
        sum += stoi(num.substr(1, 9));
      } else {
        sum += stoi(num);
      }
      num = "";
    }
    i++;
  }
  ans += sum;
}

void make_string(int bit) {
  int i = 0;
  string t("");
  irep(j, input.size()) {
    t += input[j];
    if (bit & (0x1 << j)) {
      t += "+";
    }
  }
  // t += input.back();
  // cout << t << endl;
  solve(t);
}

void make_bit(int n, int i, int bit) {
  if (n == i) {
    // cout << bit << endl;
    make_string(bit);
    return;
  }
  make_bit(n, i + 1, bit);
  make_bit(n, i + 1, bit | (0x1 << i));
}

int main() {
  cin >> input;

  make_bit(input.size() - 1, 0, 0);
  cout << ans << endl;
  return 0;
}