Problem p04041 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

  int N;
  cin >> N;
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int M = X + Y + Z;

  const ll mod = 1e9 + 7;
  map<ll, ll> dp[2];
  dp[0][0] = 1;

  ll kotae = 0;
  rep(i, N) {
    int a = i & 1;
    int b = a ^ 1;

    kotae = kotae * 10 % mod;
    for (auto x : dp[a]) {
      ll k = x.second % mod;
      ll DP = x.first;

      dp[b][0] += 3 * k;

      rep1(j, 7) {
        int p = 0;
        int x = j;
        ll tmp = DP;

        while (tmp && x < Z) {
          x += tmp % 11;
          tmp /= 11;
        }
        if (x == Z) {
          while (tmp && x < Y + Z) {
            x += tmp % 11;
            tmp /= 11;
          }
          if (x == Y + Z) {
            while (tmp && x < X + Y + Z) {
              x += tmp % 11;
              tmp /= 11;
            }
            if (x == X + Y + Z) {
              kotae += k;
              continue;
            }
          }
        }
        tmp = DP;
        ll tugi = j;
        ll kari = 11;
        x = j;
        while (tmp && x < M - 1) {
          int tmp2 = tmp % 11;
          tmp /= 11;
          x += tmp2;
          tugi += kari * tmp2;
          kari *= 11;
        }
        dp[b][tugi] += k;
      }
    }
    dp[a].clear();
  }
  co(kotae % mod);

  Would you please return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

  int N;
  cin >> N;
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int M = X + Y + Z;

  const ll mod = 1e9 + 7;
  map<ll, ll> dp[2];
  dp[0][0] = 1;

  ll kotae = 0;
  rep(i, N) {
    int a = i & 1;
    int b = a ^ 1;

    kotae = kotae * 10 % mod;
    for (auto x : dp[a]) {
      ll k = x.second % mod;
      ll DP = x.first;

      dp[b][0] += 3 * k;

      rep1(j, 7) {
        int p = 0;
        int x = j;
        ll tmp = DP;

        while (tmp && x < Z) {
          x += tmp % 11;
          tmp /= 11;
        }
        if (x == Z) {
          while (tmp && x < Y + Z) {
            x += tmp % 11;
            tmp /= 11;
          }
          if (x == Y + Z) {
            while (tmp && x < X + Y + Z) {
              x += tmp % 11;
              tmp /= 11;
            }
            if (x == X + Y + Z) {
              kotae += k;
              continue;
            }
          }
        }
        tmp = DP;
        ll tugi = j;
        ll kari = 11;
        x = j;
        while (tmp && x + tmp % 11 < M) {
          int tmp2 = tmp % 11;
          tmp /= 11;
          x += tmp2;
          tugi += kari * tmp2;
          kari *= 11;
        }
        dp[b][tugi] += k;
      }
    }
    dp[a].clear();
  }
  co(kotae % mod);

  Would you please return 0;
}