Problem p03467 (C++)

Buggy submission (status: Runtime Error):
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template <typename T> bool get_int(T &x) {
  char t = getchar();
  bool neg = false;
  x = 0;
  for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
    ;
  if (t == '-')
    neg = true, t = getchar();
  if (t == EOF)
    return false;
  for (; t <= '9' && t >= '0'; t = getchar())
    x = x * 10 + t - '0';
  if (neg)
    x = -x;
  return true;
}
template <typename T> void print_int(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  short a[20] = {}, sz = 0;
  while (x > 0)
    a[sz++] = x % 10, x /= 10;
  if (sz == 0)
    putchar('0');
  for (int i = sz - 1; i >= 0; i--)
    putchar('0' + a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a, b) (get1(a) && get1(b))
#define get3(a, b, c) (get1(a) && get2(b, c))
#define printendl(a) print_int(a), puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);

const int mod = 998244353;
int pw2[233], dp[233];
map<string, int> rem;
int calc(const string &s) {
  if (rem.find(s) != rem.end())
    return rem[s];
  int cnt = 0;
  for (int i = 0; i < (int)s.size(); i++)
    cnt += (s[i] == '1');
  //	if(cnt==0)return dp[(int)s.size()];
  int ret = calc(s.substr(1));
  if (s[0] == '1')
    ret = (ret + ret) % mod;
  int sz = (int)s.size();
  for (int l = 1; l <= sz / 2; l++) {
    string now = s.substr(0, l);
    for (int i = 2; i * l <= sz; i++) {
      for (int j = l * (i - 1); j < l * i; j++)
        if (s[j] == '0')
          now[j - (i - 1) * l] = '0';
      ret = (ret + 1ll * calc(now) * calc(s.substr(i * l))) % mod;
    }
  }
  rem[s] = ret;
  return ret;
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i < 233; i++)
    pw2[i] = pw2[i - 1] * 2 % mod;
  dp[0] = 1;
  for (int i = 1; i < 233; i++) {
    dp[i] = dp[i - 1];
    for (int j = 2; j <= i; j++)
      for (int k = j; k <= i; k += j)
        dp[i] = (dp[i] + 1ll * dp[k / j] * dp[i - k]) % mod;
  }
  string s;
  cin >> s;
  cout << calc(s);
  return 0;
}

Fixed submission:
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template <typename T> bool get_int(T &x) {
  char t = getchar();
  bool neg = false;
  x = 0;
  for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
    ;
  if (t == '-')
    neg = true, t = getchar();
  if (t == EOF)
    return false;
  for (; t <= '9' && t >= '0'; t = getchar())
    x = x * 10 + t - '0';
  if (neg)
    x = -x;
  return true;
}
template <typename T> void print_int(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  short a[20] = {}, sz = 0;
  while (x > 0)
    a[sz++] = x % 10, x /= 10;
  if (sz == 0)
    putchar('0');
  for (int i = sz - 1; i >= 0; i--)
    putchar('0' + a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a, b) (get1(a) && get1(b))
#define get3(a, b, c) (get1(a) && get2(b, c))
#define printendl(a) print_int(a), puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);

const int mod = 998244353;
int pw2[233], dp[233];
map<string, int> rem;
int calc(const string &s) {
  if (rem.find(s) != rem.end())
    return rem[s];
  if (s == "")
    return 1;
  int cnt = 0;
  for (int i = 0; i < (int)s.size(); i++)
    cnt += (s[i] == '1');
  //	if(cnt==0)return dp[(int)s.size()];
  int ret = calc(s.substr(1));
  if (s[0] == '1')
    ret = (ret + ret) % mod;
  int sz = (int)s.size();
  for (int l = 1; l <= sz / 2; l++) {
    string now = s.substr(0, l);
    for (int i = 2; i * l <= sz; i++) {
      for (int j = l * (i - 1); j < l * i; j++)
        if (s[j] == '0')
          now[j - (i - 1) * l] = '0';
      ret = (ret + 1ll * calc(now) * calc(s.substr(i * l))) % mod;
    }
  }
  rem[s] = ret;
  return ret;
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i < 233; i++)
    pw2[i] = pw2[i - 1] * 2 % mod;
  dp[0] = 1;
  for (int i = 1; i < 233; i++) {
    dp[i] = dp[i - 1];
    for (int j = 2; j <= i; j++)
      for (int k = j; k <= i; k += j)
        dp[i] = (dp[i] + 1ll * dp[k / j] * dp[i - k]) % mod;
  }
  string s;
  cin >> s;
  cout << calc(s);
  return 0;
}