Problem p02960 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF = 1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v), 0)

template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "	";
  }
  return s;
}

// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

int testDevide() {
  int n = 1;
  rep(i, 12) {
    cout << i << ":" << n % 13 << endl;
    n *= 10;
  }
}

ll dp[100005][13];
char s[100005];
static const ll MOD = 1000000007;

int solve() {
  cin >> s;
  ll n = strlen(s);
  dp[0][0] = 1;
  rep(i, n) {
    dbg(i);
    if (s[i] == '?') {
      rep(j, 10) {
        rep(k, 13) { dp[i + 1][(10 * k + j) % 13] += dp[i][k]; }
      }
    } else {
      rep(l, 13) {
        int c = s[i] - '0';
        dp[i + 1][(10 * l + c) % 13] += dp[i][l];
      }
    }
    rep(j, 13) {
      dbg(dp[i + 1][j]);
      dp[i + 1][j] %= MOD;
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}

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


Fixed submission:
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF = 1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v), 0)

template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "	";
  }
  return s;
}

// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

int testDevide() {
  int n = 1;
  rep(i, 12) {
    cout << i << ":" << n % 13 << endl;
    n *= 10;
  }
}

ll dp[100005][13];
char s[100005];
static const ll MOD = 1000000007;

int solve() {
  cin >> s;
  ll n = strlen(s);
  dp[0][0] = 1;
  rep(i, n) {
    dbg(i);
    if (s[i] == '?') {
      rep(j, 10) {
        rep(k, 13) { dp[i + 1][(10 * k + j) % 13] += dp[i][k]; }
      }
    } else {
      rep(l, 13) {
        int c = s[i] - '0';
        dp[i + 1][(10 * l + c) % 13] += dp[i][l];
      }
    }
    rep(j, 13) { dp[i + 1][j] %= MOD; }
  }
  cout << dp[n][5] << endl;
  return 0;
}

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