Language: C++


#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>{std::forward<T>(func)};
}

constexpr std::array<long long, 19> calc_pow10() {
  std::array<long long, 19> res{};
  res[0] = 1;
  for (int i: range(1, 19)) {
    res[i] = res[i - 1] * 10;
  }
  return res;
}

constexpr auto pow10 = calc_pow10();

constexpr std::array<std::array<long long, 19>, 19> calc_sum_max() {
  std::array<std::array<long long, 19>, 19> res{};
  for (int i: range(0, 19)) {
    for (int j: revrange(0, i / 2)) {
      res[i][j] += pow10[i - j - 1] - pow10[j];
      res[i][j] += res[i][j + 1];
    }
  }
  return res;
}

constexpr auto sum_max = calc_sum_max();

int main() {
  int D;
  std::cin >> D;
  long long ans = 0;
  for (int digit: range(2, 19)) {
    ans += make_fix_point([&](auto dfs, long long cur, int d) -> long long {
      int e = digit - d - 1;
      if (d > e) {
        return (cur == 0 ? 1 : 0);
      }
      if (d == e) {
        return (cur == 0 ? 10 : 0);
      }
      if (std::abs(cur) > 9 * sum_max[digit][d]) {
        return 0;
      }
      long long base = pow10[e] - pow10[d];
      long long res = 0;
      auto coeff = [&](int i) { return (d == 0 ? 9 - std::abs(i) : 10 - std::abs(i)); };
      for (int i: range(-9, 10)) {
        res += dfs(cur - base * i, d + 1) * coeff(i);
      }
      return res;
    })(D, 0);
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc:70:48: error: return type 'struct std::array<long long int, 19>' is incomplete
   70 | constexpr std::array<long long, 19> calc_pow10() {
      |                                                ^
a.cc: In function 'constexpr void calc_pow10()':
a.cc:71:29: error: variable 'std::array<long long int, 19> res' has initializer but incomplete type
   71 |   std::array<long long, 19> res{};
      |                             ^~~
a.cc:7:1: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'
    6 | #include <numeric>
  +++ |+#include <array>
    7 | 
a.cc: At global scope:
a.cc:79:16: error: deduced type 'const void' for 'pow10' is incomplete
   79 | constexpr auto pow10 = calc_pow10();
      |                ^~~~~
a.cc:81:66: error: return type 'struct std::array<std::array<long long int, 19>, 19>' is incomplete
   81 | constexpr std::array<std::array<long long, 19>, 19> calc_sum_max() {
      |                                                                  ^
a.cc: In function 'constexpr void calc_sum_max()':
a.cc:82:45: error: variable 'std::array<std::array<long long int, 19>, 19> res' has initializer but incomplete type
   82 |   std::array<std::array<long long, 19>, 19> res{};
      |                                             ^~~
a.cc:82:45: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'
a.cc: At global scope:
a.cc:92:16: error: deduced type 'const void' for 'sum_max' is incomplete
   92 | constexpr auto sum_max = calc_sum_max();
      |                ^~~~~~~