Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#include <functional>

using namespace std;

int dp[100000];

void to(int &x, int y) {
  x = min(x, y);
}

int count(int K) {
  set<int> can;
  int t = 1;
  while (!can.count(t)) {
    can.insert(t);
    t *= 10;
    t %= K;
  }
  return can.size();
}

int main() {
  int K;
  cin >> K;

  set<int, greater<int>> can;
  int t = 1;
  while (!can.count(t)) {
    can.insert(t);
    t *= 10;
    t %= K;
  }

  if (can.size() <= 1000) {
    for (int i = 0; i < K; i++) {
      dp[i] = 1e9;
    }

    for (int i : can) {
      dp[i] = 1;
    }

    for (int k : can) {
      for (int s = 0; s < 10; s++) {
        int j = k;
        for (int i = 0; i < K; i++) {
          to(dp[j], dp[i] + 1);
          if (j >= K) j -= K;
        }
      }
    }

    cout << dp[0] << endl;
  } else {
    static bitset<600000> dp;
    for (int i : can) {
      dp[i] = true;
    }
    for (int k = 2;; k++) {
      static bitset<200000> dp2;
      for (int i : can) {
        dp2 |= dp << i;
      }
      for (int i = K; i < 200000; i += K) {
        if (dp2[i]) {
          cout << k << endl;
          return 0;
        }
      }
      dp = dp2 | (dp2 >> K);
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:13: error: no match for 'operator|=' (operand types are 'std::bitset<200000>' and 'std::bitset<600000>')
   67 |         dp2 |= dp << i;
      |         ~~~~^~~~~~~~~~
In file included from a.cc:5:
/usr/include/c++/14/bitset:1056:7: note: candidate: 'std::bitset<_Nb>& std::bitset<_Nb>::operator|=(const std::bitset<_Nb>&) [with long unsigned int _Nb = 200000]'
 1056 |       operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bitset:1056:37: note:   no known conversion for argument 1 from 'std::bitset<600000>' to 'const std::bitset<200000>&'
 1056 |       operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/cstddef:168:3: note: candidate: 'constexpr std::byte& std::operator|=(byte&, byte)'
  168 |   operator|=(byte& __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:168:20: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'std::byte&'
  168 |   operator|=(byte& __l, byte __r) noexcept
      |              ~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:104:3: note: candidate: 'constexpr const std::_Ios_Fmtflags& std::operator|=(_Ios_Fmtflags&, _Ios_Fmtflags)'
  104 |   operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:104:29: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'std::_Ios_Fmtflags&'
  104 |   operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:154:3: note: candidate: 'constexpr const std::_Ios_Openmode& std::operator|=(_Ios_Openmode&, _Ios_Openmode)'
  154 |   operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:154:29: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'std::_Ios_Openmode&'
  154 |   operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:201:3: note: candidate: 'constexpr const std::_Ios_Iostate& std::operator|=(_Ios_Iostate&, _Ios_Iostate)'
  201 |   operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:201:28: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'std::_Ios_Iostate&'
  201 |   operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |              ~~~~~~~~~~~~~~^~~
a.cc:75:27: error: no match for 'operator=' (operand types are 'std::bitset<600000>' and 'std::bitset<200000>')
   75 |       dp = dp2 | (dp2 >> K);
      |                           ^
/usr/include/c++/14/bitset:804:11: note: candidate: 'constexpr std::bitset<600000>& std::bitset<600000>::operator=(const std::bitset<600000>&)'
  804 |     class bitset
      |           ^~~~~~
/usr/include/c++/14/bitset:804:11: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'const std::bitset<600000>&'
/usr/include/c++/14/bitset:804:11: note: candidate: 'constexpr std::bitset<600000>& std::bitset<600000>::operator=(std::bitset<600000>&&)'
/usr/include/c++/14/bitset:804:11: note:   no known conversion for argument 1 from 'std::bitset<200000>' to 'std::bitset<600000>&&'