Problem p03329 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;

int N;
VI c;
int dp[100010];

signed main() {
  cin >> N;

  repif(i, 1, POW(6, i) <= N) c.pb(POW(6, i));
  repif(i, 1, POW(9, i) <= N) c.pb(POW(9, i));
  c.pb(1);
  sort(ALL(c));

  fill(RNG(dp, 0, 100010), INF);

  dp[1] = 1;
  repe(i, 1, N) for (int x : c) chmin(dp[i + x], dp[i] + 1);

  cout << dp[N] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;

int N;
VI c;
int dp[100010];

signed main() {
  cin >> N;

  repif(i, 1, POW(6, i) <= N) c.pb(POW(6, i));
  repif(i, 1, POW(9, i) <= N) c.pb(POW(9, i));
  c.pb(1);
  sort(ALL(c));

  fill(RNG(dp, 0, 100010), INF);

  dp[0] = 0;
  repe(i, 0, N) {
    rep(j, 0, SIZE(c)) {
      if (N < i + c[j])
        break;
      chmin(dp[i + c[j]], dp[i] + 1);
    }
  }

  cout << dp[N] << endl;

  return 0;
}